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

Incorrect default value for start when step is negative in the slice selector #546

Closed
lukasz05 opened this issue Oct 21, 2024 · 2 comments · Fixed by #559
Closed

Incorrect default value for start when step is negative in the slice selector #546

lukasz05 opened this issue Oct 21, 2024 · 2 comments · Fixed by #559
Assignees
Labels
area: parser Related to `rsonpath-syntax` type: bug Something isn't working
Milestone

Comments

@lukasz05
Copy link

Package

Library

Describe the bug

According to RFC 9535, the default value for start depends on the sing of step and is len - 1 when step < 0. The JSONPath parser always uses 0 as the default value for start.

Minimal Reproducible Example

let query1 = rsonpath_syntax::parse("$[::-1]").unwrap();
let query2 = rsonpath_syntax::parse("$[0::-1]").unwrap();
assert_ne!(query1, query2);

Expected behavior

$[::-1] and $[0::-1] are different queries, so their ASTs generated by the parser can't be equal.
The start field of the Slice struct should probably be of type Option<Index> and set to None if the value is omitted, just like the end field.

Workarounds (optional)

No response

Proposed solution (optional)

No response

Version of the release

v0.9.1

Rust version

1.80.1

Target triple

aarch64-apple-darwin

Features enabled

default

Codegen options

No response

Additional context (optional)

No response

@lukasz05 lukasz05 added the type: bug Something isn't working label Oct 21, 2024
@github-actions github-actions bot added the acceptance: triage Waiting for owner's input label Oct 21, 2024
Copy link

Tagging @V0ldek for notifications

@V0ldek
Copy link
Member

V0ldek commented Oct 24, 2024

This is indeed a bug.

For $[::-1] the correct output should be the same as for $[-1::-1], so a start value of FromEnd(JsonNonZeroUInt(1)).

@V0ldek V0ldek added this to the v1.0.0 milestone Oct 24, 2024
@github-actions github-actions bot added acceptance: go ahead Reviewed, implementation can start and removed acceptance: triage Waiting for owner's input labels Oct 24, 2024
@V0ldek V0ldek added the area: parser Related to `rsonpath-syntax` label Oct 24, 2024
@github-actions github-actions bot removed the acceptance: go ahead Reviewed, implementation can start label Oct 26, 2024
@V0ldek V0ldek moved this from Todo to Merged in Active rq development Oct 26, 2024
@V0ldek V0ldek self-assigned this Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: parser Related to `rsonpath-syntax` type: bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

2 participants