Closed
Description
Symfony version(s) affected
7.3.0
Description
In JsonPath, the compact dot notation for segments is a shortcut making it easier to access keys that can be written as an identifier. The canonical form is to use the bracket notation with the property name as a (quoted) string: https://www.rfc-editor.org/rfc/rfc9535#name-segments
However, our JsonPath
class building an expression is always using the dot notation, without checking that the provided keys is a valid identifier.
https://github.com/symfony/symfony/blob/v7.3.0/src/Symfony/Component/JsonPath/JsonPath.php#L33
How to reproduce
use Symfony\Component\JsonPath\JsonCrawler;
use Symfony\Component\JsonPath\JsonPath;
$jsonPathExpression = (string) (new JsonPath)->key('some-prop');
dump((new JsonCrawler('{"some-prop": "example value"}'))->find($jsonPathExpression));
Possible Solution
We should either always use the bracket notation or select the notation based on the key.
Additional Context
No response