Skip to content

fix(markers): wrap malformed quoted strings as public parse errors - #1249

Merged
henryiii merged 1 commit into
pypa:mainfrom
r266-tech:fix-marker-quoted-string-public-errors
Jun 19, 2026
Merged

henryiii merged 1 commit into
pypa:mainfrom
r266-tech:fix-marker-quoted-string-public-errors

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

Malformed quoted marker strings can currently leak a raw SyntaxError from ast.literal_eval() instead of the public parser exceptions callers expect. For example, Marker('os_name == "C:\"') and Requirement('pkg; os_name == "C:\"') bypass InvalidMarker / InvalidRequirement.

This converts literal-eval failures in the quoted-string parser path into ParserSyntaxError, preserving the existing public wrappers and full source/caret diagnostics.

This addresses one malformed-literal item from #1239.

Verification

  • uv run pytest tests/test_markers.py tests/test_requirements.py -q
  • uv run ruff check src/packaging/_parser.py tests/test_markers.py tests/test_requirements.py
  • uv run ruff format --check src/packaging/_parser.py tests/test_markers.py tests/test_requirements.py
  • Codex adversarial review: reworked tests to pin exact diagnostics, final VERDICT: approve

Known scope: this does not change marker grammar; it only maps malformed quoted literals that already reach the quoted-string parser branch onto the existing public exception contract.

@henryiii henryiii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does change the error type but I think it makes sense. I'll let other have a chance to look at it first, but I think I'll approve eventually if no one has objections.

@henryiii
henryiii merged commit 6115033 into pypa:main Jun 19, 2026
59 checks passed
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.

2 participants