Skip to content

Commit 04837c0

Browse files
committed
Fix keys with Boolean names
1 parent dcda7ed commit 04837c0

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

jsonpath_ng/ext/parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ class ExtendedJsonPathLexer(lexer.JsonPathLexer):
3030

3131
t_FILTER_OP = r'=~|==?|<=|>=|!=|<|>'
3232

33-
def t_BOOL(self, t):
34-
r'true|false'
35-
t.value = True if t.value == 'true' else False
36-
return t
37-
3833
def t_SORT_DIRECTION(self, t):
3934
r',?\s*(/|\\)'
4035
t.value = t.value[-1]
@@ -47,6 +42,11 @@ def t_ID(self, t):
4742
t.type = self.reserved_words.get(t.value, 'ID')
4843
return t
4944

45+
def t_BOOL(self, t):
46+
r'true|false'
47+
t.value = True if t.value == 'true' else False
48+
return t
49+
5050
def t_FLOAT(self, t):
5151
r'-?\d+\.\d+'
5252
t.value = float(t.value)

tests/test_jsonpath.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ def test_update(parse, expression, data, update_value, expected_value):
281281
# --------
282282
#
283283
("1", {"1": "foo"}, ["foo"], ["1"]),
284+
#
285+
# Regression tests
286+
# --------
287+
#
288+
("true", {"true": 3}, [3], ["true"]),
284289
)
285290

286291

0 commit comments

Comments
 (0)