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
10 changes: 5 additions & 5 deletions jsonpath_rfc9535/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,12 @@ def tokenize(query: str) -> List[Token]:
lexer, tokens = lex(query)
lexer.run()

# Check for remaining opening brackets that have not been closes.
if tokens and tokens[-1].type_ == TokenType.ERROR:
raise JSONPathSyntaxError(tokens[-1].message, token=tokens[-1])

# Check for remaining opening brackets that have not been closed.
if lexer.bracket_stack:
ch, index = lexer.bracket_stack[0]
ch, index = lexer.bracket_stack[-1]
msg = f"unbalanced {'brackets' if ch == '[' else 'parentheses'}"
raise JSONPathSyntaxError(
msg,
Expand All @@ -524,7 +527,4 @@ def tokenize(query: str) -> List[Token]:
),
)

if tokens and tokens[-1].type_ == TokenType.ERROR:
raise JSONPathSyntaxError(tokens[-1].message, token=tokens[-1])

return tokens
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ exclude = [
"dist",
"node_modules",
"venv",
"tests/nts",
]

# Same as Black.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def env() -> JSONPathEnvironment:

def test_unclosed_selection_list(env: JSONPathEnvironment) -> None:
with pytest.raises(
JSONPathSyntaxError, match=r"unbalanced brackets, line 1, column 1"
JSONPathSyntaxError, match=r"unbalanced brackets, line 1, column 5"
):
env.compile("$[1,2")


def test_unclosed_selection_list_inside_filter(env: JSONPathEnvironment) -> None:
with pytest.raises(
JSONPathSyntaxError, match=r"unbalanced brackets, line 1, column 1"
JSONPathSyntaxError, match=r"unclosed bracketed selection, line 1, column 10"
):
env.compile("$[?@.a < 1")

Expand Down
Loading