fix: curl import fails when --cookie flags appear before URL#349
Open
lawrence3699 wants to merge 1 commit intodarrenburns:mainfrom
Open
fix: curl import fails when --cookie flags appear before URL#349lawrence3699 wants to merge 1 commit intodarrenburns:mainfrom
lawrence3699 wants to merge 1 commit intodarrenburns:mainfrom
Conversation
When a curl command contains --cookie flags before the URL (which is the format Posting's own export produces), the import parser fails to identify the URL because --cookie is not defined as an argparse argument. The cookie value gets matched as the positional URL argument instead. Add --cookie/-b, --location/-L, --no-location, and --proxy/-x to the argparse parser so their values are consumed correctly and don't interfere with URL detection. Fixes darrenburns#309
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes curl import parsing when --cookie (and other value-taking flags) appear before the URL, which previously caused the cookie value to be consumed as the positional url argument (regression/round-trip issue with Posting’s own to_curl() output).
Changes:
- Teach the curl import
argparseparser about--cookie/-b,--proxy/-x,--location/-L, and--no-locationso value-taking flags don’t clobber the URL. - Add regression tests covering cookies-before-URL, cookies+headers,
-L, and--proxy.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/posting/importing/curl.py |
Adds missing curl flags to the importer’s argparse spec so parse_known_intermixed_args assigns the correct positional URL. |
tests/test_curl_import.py |
Adds targeted regression tests ensuring URL parsing remains correct with cookies/location/proxy flags before the URL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Fixes #309.
When importing a curl command that contains
--cookieflags before the URL (e.g.curl --cookie 'session=abc' 'http://example.com'), the URL is incorrectly parsed as the cookie value. This is the exact format that Posting's ownto_curl()export produces, making exported commands fail to round-trip through import.Root cause: The
--cookieflag was not defined in the argparse parser. Sinceparse_known_intermixed_argsdoesn't know--cookietakes a value, it consumes the cookie value token as the positionalurlargument.Before:
curl --cookie 'AEC=test' 'http://google.com'→ URL ='AEC=test'After:
curl --cookie 'AEC=test' 'http://google.com'→ URL ='http://google.com'Changes
--cookie/-b,--location/-L,--no-location, and--proxy/-xto the curl import argparse parserThese flags are either used by Posting's own export or commonly appear in browser "Copy as cURL" output.