Fix union of quoted property names returning no results#268
Open
spokodev wants to merge 1 commit into
Open
Conversation
`$['x','y']` (the canonical bracketed union of quoted names) returned `[]` instead of the selected values. `toPathArray` only strips the quotes for a single-name bracket (`['name']`), so for a multi-member bracket the interior quotes survive and the union branch splits `x','y` on the comma into `["x'", "'y"]`, then looks up properties literally named `x'` and `'y`, which don't exist. Strip a surrounding quote from each comma-separated member before the lookup. Bare (`$[x,y]`) and numeric (`$[0,2]`) members have no quotes and are unchanged. Fixes the quoted forms `$['x','y']`, `$["x","y"]` and `$['x', 'y']` (issue JSONPath-Plus#159).
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.
Problem
A bracketed union of quoted property names — the canonical Goessner /
RFC-9535 form
$['x','y']— returns[]instead of the selected values:Same for
$["x","y"]and$['x', 'y']. The non-standard bare form$[x,y]works (
[1, 2]), and numeric unions$[0,2]work — only the quoted (standard)form is broken.
Root cause
toPathArrayonly strips the surrounding quotes for a single-name bracket(
['name'], via/\[['"]([^'\]]*)['"]\]/). A multi-member bracket['x','y']doesn't match that pattern, so the interior quotes survive tokenization:
The
_traceunion branch then does"x','y".split(',')→["x'", "'y"]andlooks up properties literally named
x'and'y, which don't exist →[].Fix
Strip a surrounding quote from each comma-separated member before the lookup.
Bare and numeric members carry no quotes, so they are unaffected (the strip is a
no-op for them).
Test
Added a "Union of quoted property names" case to
test/test.properties.jscovering
$['x','y'],$["x","y"],$['x', 'y']. Fails onmain, passes withthe fix; the existing suite (280 tests) is unchanged.
Closes #159.