Repository navigation
fix: look up quoted names with brackets, semicolons or quotes as written - #293
Open
simonkundrik wants to merge 1 commit into
Open
simonkundrik wants to merge 1 commit into
simonkundrik wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
toPathArraysplits the expression at those characters before the name is read:$['cd[DataLayer]']and$[']']return nothing (Selecting properties containing a square bracket seems to be impossible #225), and so does$..['phoneNumbers [1]'](Path not found when square Brackets inside of Path String #167)$["it's"]and$["'lastName'"]return nothing (Cannot resolve JSONPath has single quote #203).$["a'"]is one of the failing cases in the RFC 9535 compliance suite$['x;y']and$['a^b']return nothing$['@id']throws at the root (Error thrown when using square brackets to access property at the root of the JSON #258), and$['Name#23']throwsCannot read properties of undefined(Errors in case of special characters like '#' and undefined output with square brackets while using 'JSONPath' #173)resultType: 'path') can't be passed back in, and neither can the array form['$', 'a[b]']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 theirtoPathArrayoutput 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#23still 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.jsthat 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,tscand the mocha suite pass and coverage ofsrcstays at 100%. The only failures are the 2 cli tests, which can't runbin/jsonpath-cli.json 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).