Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/test_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ def test_error_unclosed_brace():
list(expand_patterns("test[a]{1-3"))


def test_error_open_range_missing_end():
""""{2-}" consumes the dash and finds no end: same error class as "{-2}",
not a silent expansion to zero permutations."""
with pytest.raises(ValueError, match="range end"):
list(expand_patterns("test[a-c]{2-}"))


def test_error_lone_open_bracket():
with pytest.raises(ValueError):
list(expand_patterns("["))
Expand Down
7 changes: 6 additions & 1 deletion user_scanner/core/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ def _parse_lenset(lexer: Lexer) -> Set[int]:
lexer.next()
rhs = lexer.parse_number()

if lhs is not None and rhs is not None:
# "{2-}" consumed the dash but has no end: erroring matches
# "{-2}", while skipping silently expands to zero permutations
# and the scan runs on no targets without a word.
if rhs is None:
raise ValueError('Missing range end after "-" in lenset')
if lhs is not None:
for i in range(lhs, rhs + 1):
lenset.add(i)
elif lhs is not None:
Expand Down
Loading