Repository navigation
fix: support unions that mix quoted names with other selectors - #291
Open
simonkundrik wants to merge 1 commit into
Open
simonkundrik wants to merge 1 commit into
simonkundrik wants to merge 1 commit into
Conversation
A union with a quoted name next to any other kind of selector found nothing for the quoted name: $['a',1] returned only the index, $[*,'a'] dropped the name, and $..['io.nest',out] (the last example in JSONPath-Plus#159) returned only `out`. toPathArray only kept unions of quoted names intact, so a mixed one was split at the commas with the quotes still stuck to the pieces. toPathArray now keeps any well formed union that has a quoted member intact, and _trace traces the members in order: quoted ones as literal names, the rest (indexes, slices, wildcards, bare names) as usual. Unions without quotes are unchanged, so $[x, y] still treats the space as part of the name.
This was referenced Nov 4, 2026
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.
A bracket union with a quoted name next to any other selector never matches the quoted name:
$['a',1]on{"a":1,"b":2}returns[](should be[1])$[*,'a']on{"a":"A","b":"B"}returns["A","B"](should be["A","B","A"])$..['io.nest',out], the last example in Quoted subscript can not work will with union/or subscripts. #159, returns onlyoutThe #159 fix handles unions where every member is quoted. As soon as one member is an index, slice, wildcard or bare name,
toPathArraysplits at the commas and leaves the quotes stuck to the pieces (a'and1), so the quoted name is looked up asa'. These are the two failing "basic" cases in the RFC 9535 compliance suite, where a bracketed selection takes any comma separated list of selectors.toPathArraynow keeps any well formed union that has a quoted member intact, and_tracewalks the members in order: quoted ones as literal names, everything else traced as usual (so$[*,'a']gives the wildcard matches and thena). Unions without a quoted member go through the old code, so$[x, y]still treats the space as part of the name and a stray apostrophe in a bare name ($[it's,x]) is left alone. Unions of only quoted names keep their single pass, and a 3000 row query timed about the same as before.I added a test in
test.properties.jscovering both orders, whitespace, wildcard and slice members, commas and escapes inside the quotes, path results and the #159 example. It fails on main (both VM modes) and passes now.eslint,tscand the mocha suite pass and coverage ofsrcstays at 100%. The only failures here are the 2 cli tests, which can't runbin/jsonpath-cli.json my Windows machine with or without this change. I also ran all 715 selectors from the RFC 9535 compliance suite before and after, and only those 2 changed.