fix: parse_curl mangles tokens from shlex.split with backslash-newline continuation - #18
Merged
Merged
Conversation
…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
force-pushed
the
fix/curl-shlex-newline-token
branch
from
July 26, 2026 03:58
b23a3fa to
ad35b7d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-Ht.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\\\ncontinuation as part of the following token. For example,-H 'Authorization: Bearer xxx'becomes token"\n-H"and its valueAuthorization: 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