requests icon indicating copy to clipboard operation
requests copied to clipboard

Fix: Preserve escaped quotes in cookies

Open egangi opened this issue 2 months ago • 0 comments

This PR fixes a bug in Requests where cookie values containing escaped quotes were being corrupted according to issue #6890.

Problem:

  • The original set_cookie method stripped all escaped quotes inside cookie values.
  • Example: '"159\"687"' became '159687', breaking valid cookie data, including JSON fragments or structured data.

Solution:

  • Modified set_cookie to only remove surrounding quotes while preserving escaped quotes within the value.
  • This preserves legitimate escaped characters and maintains compatibility with normal cookies.

Tests / QA:

  • test_cookie_escaped_quotes — Verifies that escaped quotes are preserved.
  • test_cookie_no_quotes — Ensures values without surrounding quotes but containing escaped quotes remain unchanged.
  • test_cookie_no_escaped_quotes — Confirms normal cookie values are stored as-is.
  • test_cookie_json_fragment — Checks that JSON fragments with escaped quotes are preserved exactly.
  • All existing Requests tests pass, and pre-commit hooks and style checks are satisfied.

egangi avatar Nov 09 '25 22:11 egangi