1
0
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:
Florian Wolfsjäger 2022-01-19 15:27:36 +01:00
parent 80779cedc0
commit dc763526bd
No known key found for this signature in database
GPG Key ID: 50B2172DEA035DFC
3 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -17,6 +17,9 @@ final class ValidJsonPointers
$this->jsonPointers = array_values($jsonPointers);
}
/**
* @throws InvalidArgumentException
*/
public function toArray(): array
{
if (! $this->validated) {

View File

@ -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']],