Skip to content

fix: look up quoted names with brackets, semicolons or quotes as written - #293

Open
simonkundrik wants to merge 1 commit into
JSONPath-Plus:mainfrom
simonkundrik:fix/quoted-name-syntax-chars
Open

simonkundrik wants to merge 1 commit into
JSONPath-Plus:mainfrom
simonkundrik:fix/quoted-name-syntax-chars

Conversation

@simonkundrik

Copy link
Copy Markdown
Contributor

Quoted names are not looked up as written when they contain a bracket, a semicolon, a caret, an apostrophe inside double quotes, a leading double quote or at sign, or a hash followed by a digit. toPathArray splits the expression at those characters before the name is read:

A single quoted name with one of those characters is now kept intact in toPathArray, with a leading backtick (the existing escape, so it works like $.*and$['*']) and looked up as it is. Names without them take the same route as before, so their toPathArray output doesn't change either, and $['*'] is still a wildcard. A name that already starts with a backtick keeps its escape meaning.

A name that starts with ( is still read as a script (that happens earlier), and unquoted $.Name#23 still fails, so #173 is only partly covered.

I know #259 reworks the path parser and lists these issues. This is a small change to the current tokenizer for the quoted cases so they work in the meantime. It doesn't touch the lines #291 and #292 change, and I ran the suite on all three branches merged together (all passing).

I added one test to test.properties.js that runs 12 names (in both quote styles where possible) through direct, nested, continued and descendant paths, wrap: false, result path round trips and array paths. It fails on main (both VM modes) and passes now. eslint, tsc and the mocha suite pass and coverage of src stays at 100%. The only failures are the 2 cli tests, which can't run bin/jsonpath-cli.js on my Windows machine, same as on main. Across every path string in the test files the only result that changed was the new test's own backtick case, and in the RFC 9535 suite only $["a'"] changed (it passes now).

Quoted names containing a bracket, a semicolon, a caret, an apostrophe
(inside double quotes), a leading double quote or at sign, or a hash
followed by a digit were not looked up as written. toPathArray splits
the expression at those characters before the name is read, so
$['cd[DataLayer]'], $["it's"], $['x;y'] and $['@id'] found nothing or
threw, and the result paths for such properties could not be fed back
into a query.

A single quoted name with one of those characters is now kept intact in
toPathArray, with a leading backtick (the existing escape) so that it is
looked up as it is. Other names take the same route as before.

Fixes JSONPath-Plus#167, fixes JSONPath-Plus#203, fixes JSONPath-Plus#225 and fixes JSONPath-Plus#258. Also covers the quoted
forms in JSONPath-Plus#173.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant