Skip to content

fix: curl import fails when --cookie flags appear before URL#349

Open
lawrence3699 wants to merge 1 commit intodarrenburns:mainfrom
lawrence3699:fix/curl-import-cookie-url
Open

fix: curl import fails when --cookie flags appear before URL#349
lawrence3699 wants to merge 1 commit intodarrenburns:mainfrom
lawrence3699:fix/curl-import-cookie-url

Conversation

@lawrence3699
Copy link
Copy Markdown

Summary

Fixes #309.

When importing a curl command that contains --cookie flags 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 own to_curl() export produces, making exported commands fail to round-trip through import.

Root cause: The --cookie flag was not defined in the argparse parser. Since parse_known_intermixed_args doesn't know --cookie takes a value, it consumes the cookie value token as the positional url argument.

Before: curl --cookie 'AEC=test' 'http://google.com' → URL = 'AEC=test'
After: curl --cookie 'AEC=test' 'http://google.com' → URL = 'http://google.com'

Changes

  • Add --cookie/-b, --location/-L, --no-location, and --proxy/-x to the curl import argparse parser
  • Add 4 regression tests covering cookie, location, and proxy flag scenarios

These flags are either used by Posting's own export or commonly appear in browser "Copy as cURL" output.

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
Copilot AI review requested due to automatic review settings April 12, 2026 19:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 argparse parser about --cookie/-b, --proxy/-x, --location/-L, and --no-location so 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.

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.

Inconsistency: curl export format incompatible with curl import

2 participants