File tree Expand file tree Collapse file tree 4 files changed +10
-18
lines changed
src/Galbar/JsonPath/Language Expand file tree Collapse file tree 4 files changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ JsonPath Language
9797=================
9898This library implements the following specification:
9999```
100- var_name¹ = /^\.([\p{L}\_\$][\w \-\$]*|\*)(.*)/u
100+ var_name¹ = /^\.([\p{L}\p{N}\ _\$][\p{L}\p{N}\_ \-\$]*|\*)(.*)/u
101101number = ([0-9]+(\.[0-9]*) | ([0-9]*\.[0-9]+))
102102string = ('\''.*?'\'' | '"'.*?'"')
103103boolean = ('true' | 'false')
@@ -128,7 +128,9 @@ length = (jsonpath | childpath) '.length'
128128in_array = value 'in' '[' value (',' value)* ']'
129129```
130130
131- ¹` var_name ` : the regexp roughly translates to "any valid JavaScript variable name".
131+ ¹` var_name ` : the regex roughly translates to "any valid JavaScript variable
132+ name", plus some quirks such as names starting with numbers or containing
133+ dashes (` - ` ).
132134
133135### Limitations on the specification:
134136* The jsonpath inside _ value_ cannot contain ` or ` , ` and ` or any comparator.
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class Regex
2323 const ROOT_OBJECT = '/^\$(.*)/ ' ;
2424
2525 // Child regex
26- const CHILD_NAME = '/^\.([\p{L}\_\$][\w \-\$]*|\*)(.*)/u ' ;
26+ const CHILD_NAME = '/^\.([\p{L}\p{N}\ _\$][\p{L}\p{N}\_ \-\$]*|\*)(.*)/u ' ;
2727 const RECURSIVE_SELECTOR = '/^\.\.(.+)/u ' ;
2828
2929 // Array expressions
@@ -32,7 +32,7 @@ class Regex
3232 const LENGTH = '/^(.*)\.length$/ ' ;
3333
3434 // Object expression
35- const CHILD_NAME_LIST = '/^(?:([\w\ _\$^\d ][\w\ -\$]*? |".*?"| \'.*? \')(\s*,\s*([\w\ _\$^\d ][\w \-\$]*|".*?"| \'.*? \'))*)$/u ' ;
35+ const CHILD_NAME_LIST = '/^(?:([\p{L}\p{N}\ _\$][\p{L}\p{N}\_\ -\$]*|".*?"| \'.*? \')(\s*,\s*([\p{L}\p{N}\ _\$][\p{L}\p{N}\_ \-\$]*|".*?"| \'.*? \'))*)$/u ' ;
3636
3737 // Conditional expressions
3838 const EXPR_STRING = '/^(?: \'(.*) \'|"(.*)")$/ ' ;
Original file line number Diff line number Diff line change 2727 */
2828class JsonObjectIssue37Test extends \PHPUnit_Framework_TestCase
2929{
30- /**
31- * This library explicitly only supports valid JavaScript variable names with the dot notation.
32- *
33- * This is not a bug but a feature
34- */
3530 public function testCase1 ()
3631 {
3732 $ jsonObject = new JsonObject ('{"a": "first", "2": "second", "b": "third"} ' );
38- $ exception = null ;
39- try {
40- $ jsonObject ->get ('$.2 ' );
41- } catch (InvalidJsonPathException $ e ) {
42- $ exception = $ e ;
43- }
44- $ this ->assertEquals ($ exception ->getMessage (), "Error in JSONPath near '.2' " );
33+ $ result = $ jsonObject ->get ('$.2 ' );
34+ $ expected = ["second " ];
35+ $ this ->assertEquals ($ expected , $ result );
4536 }
4637
4738 /**
Original file line number Diff line number Diff line change @@ -1172,8 +1172,7 @@ public function testParsingErrorsProvider()
11721172 array ("$.store.book[?(@.title in ['foo')] " , "[?(@.title in ['foo')] " ),
11731173 array ("$.store.book[?(@.title in 'foo'])] " , "[?(@.title in 'foo'])] " ),
11741174 array ("$.store.book[?(@.title in 'foo')] " , " in 'foo' " ),
1175- array ("$.store.book[?(@.title ['foo'])] " , " ['foo'] " ),
1176- array ("$.2 " , ".2 " ),
1175+ array ("$.store.book[?(@.title ['foo'])] " , " ['foo'] " )
11771176 );
11781177 }
11791178
You can’t perform that action at this time.
0 commit comments