mirror of
https://github.com/halaxa/json-machine.git
synced 2025-01-17 21:18:23 +01:00
Fix JSON stream parser test for root JSON pointer
This commit is contained in:
parent
80779cedc0
commit
dc763526bd
@ -368,11 +368,13 @@ class Parser implements \IteratorAggregate, PositionAware
|
||||
throw new JsonMachineException('getCurrentJsonPointer() must not be called outside of a loop');
|
||||
}
|
||||
|
||||
$currentJsonPointer = implode('/', array_map(function ($jsonPointerPart) {
|
||||
$currentJsonPointer = array_map(function ($jsonPointerPart) {
|
||||
return str_replace(['~', '/'], ['~0', '~1'], $jsonPointerPart);
|
||||
}, $this->currentJsonPath));
|
||||
}, $this->currentJsonPath);
|
||||
|
||||
return ($currentJsonPointer !== '') ? '/'.$currentJsonPointer : '';
|
||||
array_unshift($currentJsonPointer, '');
|
||||
|
||||
return implode('/', $currentJsonPointer);
|
||||
}
|
||||
|
||||
public function getMatchedJsonPointer(): string
|
||||
|
@ -17,6 +17,9 @@ final class ValidJsonPointers
|
||||
$this->jsonPointers = array_values($jsonPointers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
if (! $this->validated) {
|
||||
|
@ -324,6 +324,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
return [
|
||||
['', '{"c":1,"d":2}', ['', '']],
|
||||
['/', '{"":{"c":1,"d":2}}', ['/', '/']],
|
||||
['/~0', '{"~":{"c":1,"d":2}}', ['/~0', '/~0']],
|
||||
['/~1', '{"/":{"c":1,"d":2}}', ['/~1', '/~1']],
|
||||
['/~1/c', '{"/":{"c":[1,2],"d":2}}', ['/~1/c', '/~1/c']],
|
||||
|
Loading…
x
Reference in New Issue
Block a user