Skip to content

fix(curl_parser): keep all cookies when -b/--cookie is repeated - #1977

Open
navtej21 wants to merge 1 commit into
foss42:mainfrom
navtej21:fix-repeated-cookie-flags
Open

navtej21 wants to merge 1 commit into
foss42:mainfrom
navtej21:fix-repeated-cookie-flags

Conversation

@navtej21

@navtej21 navtej21 commented Dec 3, 2026

Copy link
Copy Markdown

PR Description

Repeated -b / --cookie flags were dropped during cURL import: only the last
value was kept. curl sends all of them.

Cause: in packages/curl_parser/lib/models/curl.dart, cookie was registered
with addOption (single value), so each repeated flag overwrote the previous one.

Fix:

  • Register cookie with addMultiOption('cookie', abbr: 'b', splitCommas: false)
    (same approach as fix(curl_parser): prevent splitting form data values on commas (#1951) #1952 for -F).
  • Join all values with ; into the existing String? cookie field. This matches
    the Cookie header curl sends, so no model or toCurlString() changes are needed.
  • When -b is not used, cookie stays null as before.
Command Before After
-b "a=1" -b "b=2" b=2 a=1; b=2
-b "a=1" -b "b=2" -b "c=3" c=3 a=1; b=2; c=3
--cookie "a=1" --cookie "b=2" b=2 a=1; b=2
-b "a=1; b=2" -b "c=3" c=3 a=1; b=2; c=3
-b "a=1; b=2" (single) a=1; b=2 a=1; b=2 (unchanged)

AI assistance: I used Claude Code to explore the parser code and draft tests.
I've reviewed and understand all changes.

Related Issues

Video Demo

  • Video demonstrating before and after the fix.

https://screenrec.com/share/CAzGfQknvY (video-proof)

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Note: tested on Flutter 3.44.9 (meets the project's >=3.41.2 requirement).

Added/updated tests?

We encourage you to add relevant test cases.

  • Yes

Added a repeated -b / --cookie flags test group in
packages/curl_parser/test/curl_parser_test.dart:

  • two / three repeated -b flags
  • repeated --cookie (long form)
  • multi-cookie -b followed by another -b
  • regression: single -b with multiple cookies, and = inside a cookie value

All curl_parser tests pass (89 tests).

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

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.

[Bug] cURL import keeps only the last cookie when -b/--cookie is repeated

1 participant