Skip to content

fix: parse_curl mangles tokens from shlex.split with backslash-newline continuation - #18

Merged
Fly143 merged 1 commit into
Fly143:mainfrom
NatsUIJM:fix/curl-shlex-newline-token
Jul 27, 2026
Merged

fix: parse_curl mangles tokens from shlex.split with backslash-newline continuation#18
Fly143 merged 1 commit into
Fly143:mainfrom
NatsUIJM:fix/curl-shlex-newline-token

Conversation

@NatsUIJM

Copy link
Copy Markdown
Contributor

Problem

When users copy cURL from browser DevTools (Copy as cURL), the multi-line backslash-newline continuations cause shlex.split() to produce tokens like "\n-H" instead of the expected "-H".

These malformed tokens fail both:

  • t in ("-H", "--header") — token is \n-H, not -H
  • t.startswith("-") — token starts with \n, not -

As a result, all headers are silently dropped, and the user sees: 未从 cURL 提取到 Token,请确认 Authorization header.

Root Cause

shlex.split() preserves the newline from \\\n continuation as part of the following token. For example, -H 'Authorization: Bearer xxx' becomes token "\n-H" and its value Authorization: Bearer xxx.

Fix

Strip leading whitespace from every token and filter out empty tokens before the main parsing loop (3 lines added).

Verification

Tested with a real cURL command copied from Chrome DevTools (20 headers, including Cookie with special chars, x-ds-pow-response, etc.):

Before: 0 headers extracted, token missing
After: 20 headers extracted, token and session_id correctly parsed

…slash-newline

When copying cURL from browser DevTools (Copy as cURL), multi-line
\\\n continuations cause shlex.split to produce tokens like "\n-H"
instead of "-H".  These tokens fail both t in ("-H", "--header") and
t.startswith("-"), causing the entire header block to be silently dropped
and cURL import to fail with "未从 cURL 提取到 Token".

Strip only leading '\n' (not arbitrary whitespace) from each parsed
token, then drop empty tokens before the main parsing loop.

Fixes Fly143#17
@NatsUIJM
NatsUIJM force-pushed the fix/curl-shlex-newline-token branch from b23a3fa to ad35b7d Compare July 26, 2026 03:58
@Fly143
Fly143 merged commit 44e44f6 into Fly143:main Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants