Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate results when a wildcard runs over a singleton list with a complex value #96

Closed
V0ldek opened this issue Feb 15, 2023 · 1 comment · Fixed by #100
Closed

Duplicate results when a wildcard runs over a singleton list with a complex value #96

V0ldek opened this issue Feb 15, 2023 · 1 comment · Fixed by #100
Labels
area: selector Support for a JSONPath selector good first issue Good for newcomers help wanted External contributions welcome type: bug Something isn't working
Milestone

Comments

@V0ldek
Copy link
Member

V0ldek commented Feb 15, 2023

Describe the bug
If the query ends with a wildcard selector and it is applied to a list with a singleton complex value that value is matched twice.

MRE

rsonpath '$.a.*'
{
  "a": [{}]
}
[10,10]

Expected behavior
Correct result here is [10].

Workarounds (optional)
Duplications can be removed from the bytes result, but not from count.

Proposed solution (optional)
The issue is in the handle_opening code in the main engine:

https://github.com/V0ldek/rsonpath/blob/9956fede97d95433ff6549a71e3a5ae58d2703e0/crates/rsonpath-lib/src/engine/main.rs#L315-L337

The report at line 330 is unconditional, which causes a complex value to be accepted first here, and then again when its Opening character is processed in the main loop. This should be behind a condition checking if the next event is not Opening.

Same issue is in the recursive engine:

https://github.com/V0ldek/rsonpath/blob/9956fede97d95433ff6549a71e3a5ae58d2703e0/crates/rsonpath-lib/src/engine/recursive.rs#L190-L205

Desktop (please complete the following information):

  • Rust version: 1.67.0
  • Target triple: x86_64-unknown-linux-gnu
  • Features: default
  • Version: v0.3.0
@V0ldek V0ldek added the type: bug Something isn't working label Feb 15, 2023
@github-actions github-actions bot added the acceptance: triage Waiting for owner's input label Feb 15, 2023
@github-actions
Copy link

Tagging @V0ldek for notifications

@V0ldek V0ldek added acceptance: go ahead Reviewed, implementation can start area: selector Support for a JSONPath selector help wanted External contributions welcome good first issue Good for newcomers mod: engine and removed acceptance: triage Waiting for owner's input labels Feb 15, 2023
@V0ldek V0ldek added this to the v1.0.0 milestone Feb 15, 2023
V0ldek added a commit that referenced this issue Feb 15, 2023
If the query ended with a wildcard selector and was applied
to a list with a singleton complex value,
that value was being matched twice.

Related: #96
V0ldek added a commit that referenced this issue Feb 15, 2023
* fix: duplicate results with `.*` on singleton list

If the query ended with a wildcard selector and was applied
to a list with a singleton complex value,
that value was being matched twice.

Related: #96
@github-actions github-actions bot removed the acceptance: go ahead Reviewed, implementation can start label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: selector Support for a JSONPath selector good first issue Good for newcomers help wanted External contributions welcome type: bug Something isn't working
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

1 participant