Skip to content

fix: support unions that mix quoted names with other selectors - #291

Open
simonkundrik wants to merge 1 commit into
JSONPath-Plus:mainfrom
simonkundrik:fix/mixed-union
Open

simonkundrik wants to merge 1 commit into
JSONPath-Plus:mainfrom
simonkundrik:fix/mixed-union

Conversation

@simonkundrik

Copy link
Copy Markdown
Contributor

A bracket union with a quoted name next to any other selector never matches the quoted name:

The #159 fix handles unions where every member is quoted. As soon as one member is an index, slice, wildcard or bare name, toPathArray splits at the commas and leaves the quotes stuck to the pieces (a' and 1), so the quoted name is looked up as a'. These are the two failing "basic" cases in the RFC 9535 compliance suite, where a bracketed selection takes any comma separated list of selectors.

toPathArray now keeps any well formed union that has a quoted member intact, and _trace walks the members in order: quoted ones as literal names, everything else traced as usual (so $[*,'a'] gives the wildcard matches and then a). 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.js covering 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, tsc and the mocha suite pass and coverage of src stays at 100%. The only failures here are the 2 cli tests, which can't run bin/jsonpath-cli.js on 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.

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