8000 * Allows the hyphen to be part of the field. · jeremydw/python-jsonpath-rw@409b3d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 409b3d0

Browse files
committed
* Allows the hyphen to be part of the field.
Allows IDs to contain a hyphen (but not to begin with one).
1 parent 97c6823 commit 409b3d0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

jsonpath_rw/lexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def tokenize(self, string):
5757
t_ignore = ' \t'
5858

5959
def t_ID(self, t):
60-
r'[a-zA-Z_@][a-zA-Z0-9_@]*'
60+
r'[a-zA-Z_@][a-zA-Z0-9_@\-]*'
6161
t.type = self.reserved_words.get(t.value, 'ID')
6262
return t
6363

tests/test_jsonpath.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from jsonpath_rw.parser import parse
77
from jsonpath_rw.jsonpath import *
8+
from jsonpath_rw.lexer import JsonPathLexerError
89

910
class TestDatumInContext(unittest.TestCase):
1011
"""
@@ -161,6 +162,16 @@ def test_parent_value(self):
161162
self.check_cases([('foo.baz.`parent`', {'foo': {'baz': 3}}, [{'baz': 3}]),
162163
('foo.`parent`.foo.baz.`parent`.baz.bizzle', {'foo': {'baz': {'bizzle': 5}}}, [5])])
163164

165+
def test_hyphen_key(self):
166+
self.check_cases([('foo.bar-baz', {'foo': {'bar-baz': 3}}, [3]),
167+
('foo.[bar-baz,blah-blah]', {'foo': {'bar-baz': 3, 'blah-blah':5}},
168+
[3,5])])
169+
with self.assertRaises(JsonPathLexerError):
170+
self.check_cases([('foo.-baz', {'foo': {'-baz': 8}}, [8])])
171+
172+
173+
174+
164175
#
165176
# Check that the paths for the data are correct.
166177
# FIXME: merge these tests with the above, since the inputs are the same anyhow

0 commit comments

Comments
 (0)
0