summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenn Knowles <kenn.knowles@gmail.com>2013-08-28 19:04:38 -0700
committerKenn Knowles <kenn.knowles@gmail.com>2013-08-28 19:04:38 -0700
commit0e46fb03006c628046c89765439e6a21a22abf73 (patch)
treec2d51abbb007dc66887e3c3c70104b3d34a3ffd8
parent97c6823bbe1ac13a152478416e07b5beb5a3744d (diff)
parentf02155b629760b74ba52d2ebc52052ffec5883bf (diff)
downloadjsonpath-rw-0e46fb03006c628046c89765439e6a21a22abf73.tar.gz
Merge pull request #9 from jfardello/master
* Allows the hyphen to be part of the field.
-rw-r--r--jsonpath_rw/lexer.py2
-rw-r--r--tests/test_jsonpath.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/jsonpath_rw/lexer.py b/jsonpath_rw/lexer.py
index 9a70934..bfa570a 100644
--- a/jsonpath_rw/lexer.py
+++ b/jsonpath_rw/lexer.py
@@ -57,7 +57,7 @@ class JsonPathLexer(object):
t_ignore = ' \t'
def t_ID(self, t):
- r'[a-zA-Z_@][a-zA-Z0-9_@]*'
+ r'[a-zA-Z_@][a-zA-Z0-9_@\-]*'
t.type = self.reserved_words.get(t.value, 'ID')
return t
diff --git a/tests/test_jsonpath.py b/tests/test_jsonpath.py
index 0c496cc..bf3d5c6 100644
--- a/tests/test_jsonpath.py
+++ b/tests/test_jsonpath.py
@@ -5,6 +5,7 @@ from jsonpath_rw import jsonpath # For setting the global auto_id_field flag
from jsonpath_rw.parser import parse
from jsonpath_rw.jsonpath import *
+from jsonpath_rw.lexer import JsonPathLexerError
class TestDatumInContext(unittest.TestCase):
"""
@@ -161,6 +162,16 @@ class TestJsonPath(unittest.TestCase):
self.check_cases([('foo.baz.`parent`', {'foo': {'baz': 3}}, [{'baz': 3}]),
('foo.`parent`.foo.baz.`parent`.baz.bizzle', {'foo': {'baz': {'bizzle': 5}}}, [5])])
+ def test_hyphen_key(self):
+ self.check_cases([('foo.bar-baz', {'foo': {'bar-baz': 3}}, [3]),
+ ('foo.[bar-baz,blah-blah]', {'foo': {'bar-baz': 3, 'blah-blah':5}},
+ [3,5])])
+ self.assertRaises(JsonPathLexerError, self.check_cases,
+ [('foo.-baz', {'foo': {'-baz': 8}}, [8])])
+
+
+
+
#
# Check that the paths for the data are correct.
# FIXME: merge these tests with the above, since the inputs are the same anyhow