diff --git a/code/models/fieldtypes/JSONText.php b/code/models/fieldtypes/JSONText.php index 9aa753f..5adcc2d 100755 --- a/code/models/fieldtypes/JSONText.php +++ b/code/models/fieldtypes/JSONText.php @@ -553,7 +553,7 @@ public function isValidOperator($operator) */ public function isValidExpression($expression) { - return (bool) preg_match("#^\\$\.#", $expression); + return (bool) preg_match("#^(\\*|\[\d:\d:\d\]|\\$\.+[^\d]+)#", $expression); } /** diff --git a/tests/JSONTextTest.php b/tests/JSONTextTest.php index 5dc2a82..72bba15 100755 --- a/tests/JSONTextTest.php +++ b/tests/JSONTextTest.php @@ -12,15 +12,21 @@ class JSONTextTest extends SapphireTest { /** * @todo There are a ton more permutations of a JSONPath regex - * See the walk() method in JSONStore + * See the trace() method in JSONPath for more examples to work from */ public function testIsValidExpression() { $field = JSONText::create('MyJSON'); $this->assertTrue($field->isValidExpression('$..')); + $this->assertTrue($field->isValidExpression('*')); $this->assertTrue($field->isValidExpression('$.[2]')); $this->assertTrue($field->isValidExpression('$.cars.american[*]')); + $this->assertTrue($field->isValidExpression('[0:1:1]')); + $this->assertFalse($field->isValidExpression('[0:1:]')); + $this->assertFalse($field->isValidExpression('[0:1:1')); + $this->assertFalse($field->isValidExpression('')); + $this->assertFalse($field->isValidExpression('$.1.cars.american[*]')); $this->assertFalse($field->isValidExpression('$')); $this->assertFalse($field->isValidExpression('$[2]')); }