Skip to content

fix(markers): reject backslashes in marker values - #1403

Open
WSks-ui wants to merge 2 commits into
pypa:mainfrom
WSks-ui:fix-marker-serialization
Open

fix(markers): reject backslashes in marker values#1403
WSks-ui wants to merge 2 commits into
pypa:mainfrom
WSks-ui:fix-marker-serialization

Conversation

@WSks-ui

@WSks-ui WSks-ui commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #1399.

Backslashes are currently accepted in quoted marker values, but they are interpreted as Python string escapes during parsing and emitted without escaping during serialization. As a result, a marker can change meaning after str(marker) and reparsing.

Reject unsupported backslashes while parsing marker values, following the marker grammar and the guidance in #1399. This prevents invalid input from silently changing semantics during serialization while preserving the existing output for valid markers.

Tests:

  • Added marker parsing regressions for single and double quotes with one and two backslashes.
  • Added a metadata serialization regression for Metadata.as_rfc822().
  • The full test suite and property tests pass locally.
  • Ruff, targeted mypy checks, build, and twine check --strict pass locally.

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.

Value.serialize() does not escape backslashes, so str(Marker(x)) can re-parse to a marker that evaluates differently

1 participant