Skip to content

Commit ce79b96

Browse files
committed
Simplified logic
+ Updated README
1 parent c3ec17d commit ce79b96

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ The original JsonPath implementations is available at [http://code.google.com/p/
139139

140140
Changelog
141141
---------
142+
### 0.7.1
143+
- Fixed issues with empty tokens (`['']` and `[""]`)
144+
- Fixed TypeError in AccessHelper::keyExists
145+
- Improved QueryTest
142146

143147
### 0.7.0
144148
🔻 Breaking changes ahead:

src/JSONPathLexer.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class JSONPathLexer
2929
public const MATCH_QUERY_RESULT = '\s* \( .+? \) \s*'; // Eg. ?(@.length - 1)
3030
public const MATCH_QUERY_MATCH = '\s* \?\(.+?\) \s*'; // Eg. ?(@.foo = "bar")
3131
public const MATCH_INDEX_IN_SINGLE_QUOTES = '\s* \' (.+?)? \' \s*'; // Eg. 'bar'
32-
public const MATCH_INDEX_IN_DOUBLE_QUOTES = '\s* " (.+?)? " \s*'; // Eg. 'bar'
32+
public const MATCH_INDEX_IN_DOUBLE_QUOTES = '\s* " (.+?)? " \s*'; // Eg. "bar"
3333

3434
/**
3535
* The expression being lexed.
@@ -206,16 +206,10 @@ protected function createToken(string $value): JSONPathToken
206206
$tokenValue = substr($tokenValue, 2, -1);
207207

208208
$ret = new JSONPathToken(JSONPathToken::T_QUERY_MATCH, $tokenValue);
209-
} elseif (preg_match('/^' . static::MATCH_INDEX_IN_SINGLE_QUOTES . '$/xu', $tokenValue, $matches)) {
210-
if (isset($matches[1])) {
211-
$tokenValue = $matches[1];
212-
$tokenValue = trim($tokenValue);
213-
} else {
214-
$tokenValue = '';
215-
}
216-
217-
$ret = new JSONPathToken(JSONPathToken::T_INDEX, $tokenValue);
218-
} elseif (preg_match('/^' . static::MATCH_INDEX_IN_DOUBLE_QUOTES . '$/xu', $tokenValue, $matches)) {
209+
} elseif (
210+
preg_match('/^' . static::MATCH_INDEX_IN_SINGLE_QUOTES . '$/xu', $tokenValue, $matches) ||
211+
preg_match('/^' . static::MATCH_INDEX_IN_DOUBLE_QUOTES . '$/xu', $tokenValue, $matches)
212+
) {
219213
if (isset($matches[1])) {
220214
$tokenValue = $matches[1];
221215
$tokenValue = trim($tokenValue);

0 commit comments

Comments
 (0)