Skip to content

Commit

Permalink
Ensure that the entire string is consumed with parse_marker
Browse files Browse the repository at this point in the history
Co-Authored-By: Malte Werschy <werschy.m@gmail.com>
  • Loading branch information
pradyunsg and mwerschy committed Apr 12, 2023
1 parent 30d4a1c commit be5b736
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Expand Up @@ -4,7 +4,7 @@ Changelog
*unreleased*
~~~~~~~~~~~~

No unreleased changes.
* Enforce that the entire marker string is parsed (:issue:`687`)

23.1 - 2023-04-12
~~~~~~~~~~~~~~~~~
Expand Down
8 changes: 7 additions & 1 deletion src/packaging/_parser.py
Expand Up @@ -252,7 +252,13 @@ def _parse_version_many(tokenizer: Tokenizer) -> str:
# Recursive descent parser for marker expression
# --------------------------------------------------------------------------------------
def parse_marker(source: str) -> MarkerList:
return _parse_marker(Tokenizer(source, rules=DEFAULT_RULES))
return _parse_full_marker(Tokenizer(source, rules=DEFAULT_RULES))


def _parse_full_marker(tokenizer: Tokenizer) -> MarkerList:
retval = _parse_marker(tokenizer)
tokenizer.expect("END", expected="end of marker expression")
return retval


def _parse_marker(tokenizer: Tokenizer) -> MarkerList:
Expand Down
1 change: 1 addition & 0 deletions tests/test_markers.py
Expand Up @@ -167,6 +167,7 @@ def test_parses_valid(self, marker_string):
"(python_version)",
"python_version >= 1.0 and (python_version)",
'(python_version == "2.7" and os_name == "linux"',
'(python_version == "2.7") with random text',
],
)
def test_parses_invalid(self, marker_string):
Expand Down

0 comments on commit be5b736

Please sign in to comment.