Skip to content

Commit 7adc284

Browse files
committed
Exclude non-ascii digits when lexing indexes and ints
1 parent 85e6207 commit 7adc284

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

jsonpath_rfc9535/lex.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
RE_WHITESPACE = re.compile(r"[ \n\r\t]+")
1818
RE_PROPERTY = re.compile(r"[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*")
19-
RE_INDEX = re.compile(r"-?\d+")
19+
RE_INDEX = re.compile(r"-?[0-9]+")
2020
RE_INT = re.compile(r"-?[0-9]+")
21-
RE_EXPONENT = re.compile(r"e[+-]?\d+")
22-
RE_NEGATIVE_EXPONENT = re.compile(r"e-\d+")
21+
RE_EXPONENT = re.compile(r"e[+-]?[0-9]+")
22+
RE_NEGATIVE_EXPONENT = re.compile(r"e-[0-9]+")
2323
RE_FUNCTION_NAME = re.compile(r"[a-z][a-z_0-9]*")
2424
RE_AND = re.compile(r"&&")
2525
RE_OR = re.compile(r"\|\|")
@@ -158,9 +158,10 @@ def lex_root(l: Lexer) -> Optional[StateFn]: # noqa: D103
158158
return lex_segment
159159

160160

161-
def lex_segment(l: Lexer) -> Optional[StateFn]: # noqa: D103
161+
def lex_segment(l: Lexer) -> Optional[StateFn]: # noqa: D103, PLR0911
162162
if l.ignore_whitespace() and not l.peek():
163163
l.error("unexpected trailing whitespace")
164+
return None
164165

165166
c = l.next()
166167

@@ -281,7 +282,7 @@ def lex_inside_bracketed_segment(l: Lexer) -> Optional[StateFn]: # noqa: PLR091
281282
l.backup()
282283

283284
if l.accept_match(RE_INDEX):
284-
# Index selector of part of a slice selector.
285+
# Index selector or part of a slice selector.
285286
l.emit(TokenType.INDEX)
286287
continue
287288

0 commit comments

Comments
 (0)