Skip to content

Commit

Permalink
Merge pull request #5 from jaimelopez/FEATURE-allows-minus-character-…
Browse files Browse the repository at this point in the history
…within-property-name

[FEATURE] Allows minus character within property name
  • Loading branch information
Alessio Linares authored Aug 7, 2017
2 parents dbb9140 + da6a19b commit 9a4d3aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ JsonPath Language
=================
This library implements the following specification:
```
var_name = [a-zA-Z\_\$][\w\$]*
var_name = [a-zA-Z\_\$][\w\-\$]*
number = ([0-9]+(\.[0-9]*) | ([0-9]*\.[0-9]+))
string = ('\''.*?'\'' | '"'.*?'"')
boolean = ('true' | 'false')
Expand Down
6 changes: 3 additions & 3 deletions src/Skyscanner/JsonPath/JsonObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ class JsonObject
const RE_ROOT_OBJECT = '/^\$(.*)/';

// Child regex
const RE_CHILD_NAME = '/^\.([a-zA-Z\_\$][\w\$]*|\*)(.*)/';
const RE_RECURSIVE_SELECTOR = '/^\.\.([a-zA-Z\_\$][\w\$]*|\*)(.*)/';
const RE_CHILD_NAME = '/^\.([a-zA-Z\_\$][\w\-\$]*|\*)(.*)/';
const RE_RECURSIVE_SELECTOR = '/^\.\.([a-zA-Z\_\$][\w\-\$]*|\*)(.*)/';

// Array expressions
const RE_ARRAY_INTERVAL = '/^(?:(-?\d*:-?\d*)|(-?\d*:-?\d*:-?\d*))$/';
const RE_INDEX_LIST = '/^(-?\d+)(\s*,\s*-?\d+)*$/';
const RE_LENGTH = '/^(.*)\.length$/';

// Object expression
const RE_CHILD_NAME_LIST = '/^(:?([a-zA-Z\_\$][\w\$]*?|".*?"|\'.*?\')(\s*,\s*([a-zA-Z\_\$][\w\$]*|".*?"|\'.*?\'))*)$/';
const RE_CHILD_NAME_LIST = '/^(:?([a-zA-Z\_\$][\w\-\$]*?|".*?"|\'.*?\')(\s*,\s*([a-zA-Z\_\$][\w\-\$]*|".*?"|\'.*?\'))*)$/';

// Conditional expressions
const RE_COMPARISON = '/^(.+)\s*(==|!=|<=|>=|<|>|=\~)\s*(.+)$/';
Expand Down
39 changes: 26 additions & 13 deletions tests/Skyscanner/JsonPath/JsonObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class JsonPathTest extends \PHPUnit_Framework_TestCase
"color": "red",
"price": 19.95,
"available": true,
"model": null
"model": null,
"sku-number": "BCCLE-0001-RD"
}
},
"authors": [
Expand Down Expand Up @@ -139,13 +140,18 @@ public function testGetProvider()
array(19.95),
"$.store.bicycle.price"
),
array(
array("BCCLE-0001-RD"),
"$.store.bicycle.sku-number"
),
array(
array(
array(
"color" => "red",
"price" => 19.95,
"available" => true,
"model" => null
"model" => null,
"sku-number" => "BCCLE-0001-RD"
)
),
"$.store.bicycle"
Expand Down Expand Up @@ -220,7 +226,8 @@ public function testGetProvider()
"red",
19.95,
true,
null
null,
"BCCLE-0001-RD"
),
"$.store.bicycle.*"
),
Expand Down Expand Up @@ -288,13 +295,13 @@ public function testGetProvider()
array(
"red"
),
"$..*[?(@.length <= 4)].color"
"$..*[?(@.length <= 5)].color"
),
array(
array(
"red"
),
"$..*[?(@.length <= 4.0)].color"
"$..*[?(@.length <= 5.0)].color"
),
array(
array(
Expand Down Expand Up @@ -360,7 +367,8 @@ public function testGetProvider()
"color" => "red",
"price" => 19.95,
"available" => true,
"model" => null
"model" => null,
"sku-number" => "BCCLE-0001-RD"
)
),
"$.store[?(@.*.length == 3)]",
Expand Down Expand Up @@ -417,7 +425,8 @@ public function testSmartGetProvider()
"color" => "red",
"price" => 19.95,
"available" => true,
"model" => null
"model" => null,
"sku-number" => "BCCLE-0001-RD"
),
"$.store.bicycle"
),
Expand Down Expand Up @@ -491,7 +500,8 @@ public function testSmartGetProvider()
"red",
19.95,
true,
null
null,
"BCCLE-0001-RD"
),
"$.store.bicycle.*"
),
Expand Down Expand Up @@ -559,13 +569,13 @@ public function testSmartGetProvider()
array(
"red"
),
"$..*[?(@.length <= 4)].color"
"$..*[?(@.length <= 5)].color"
),
array(
array(
"red"
),
"$..*[?(@.length <= 4.0)].color"
"$..*[?(@.length <= 5.0)].color"
),
array(
array(
Expand Down Expand Up @@ -631,7 +641,8 @@ public function testSmartGetProvider()
"color" => "red",
"price" => 19.95,
"available" => true,
"model" => null
"model" => null,
"sku-number" => "BCCLE-0001-RD"
)
),
"$.store[?(@.*.length == 3)]",
Expand Down Expand Up @@ -746,7 +757,8 @@ public function testAdd($smartGet)
'price' => 19.95,
'type' => 'BMX',
'available' => true,
'model' => null
'model' => null,
"sku-number" => "BCCLE-0001-RD"
)
);
$expected = $smartGet ? $expected[0] : $expected;
Expand Down Expand Up @@ -794,7 +806,8 @@ public function testRemove($smartGet)
],
"bicycle": {
"color": "red",
"model": null
"model": null,
"sku-number": "BCCLE-0001-RD"
}
},
"authors": [
Expand Down

0 comments on commit 9a4d3aa

Please sign in to comment.