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

fix: remove dead code for index nested start keys #24

Merged
merged 1 commit into from
Jun 23, 2024
Merged

fix: remove dead code for index nested start keys #24

merged 1 commit into from
Jun 23, 2024

Conversation

43081j
Copy link
Owner

@43081j 43081j commented Jun 23, 2024

When using index nesting, the parse loop visits [ and computes keys only if we didn't just pass a ].

This is to capture the start of such a key. For example, foo[bar][baz] would result in the only occurrence of this being foo[.

Since a syntactically valid indexed key should only have one of these (at the start), lastKey should always be undefined at that point. So we can remove the check.

cc @PondWader just one i noticed after merging. if you get a spare 5 mins, could you check i'm making sense here 👀

@PondWader
Copy link
Contributor

PondWader commented Jun 23, 2024

This did actually occur to me too, however the current parser would accept something like foo[bar]baz[qux]=x which isn't syntactically valid, but I decided to just keep parsing this for backwards compatibility. I think this would be a totally reasonable change to make and would match the behavior of qs.

@43081j
Copy link
Owner Author

43081j commented Jun 23, 2024

I suspect we could change it without a breaking version since I didn't intentionally support the invalid syntax

So if it seems sensible, I'm happy with it too

I'll add a test for those cases at least though

When using index nesting, the parse loop visits `[` and computes keys
_only if_ we didn't just pass a `]`.

This is to capture the start of such a key. For example, `foo[bar][baz]`
would result in the only occurrence of this being `foo[`.

Since a syntactically valid indexed key should only have one of these
(at the start), `lastKey` should always be `undefined` at that point. So
we can remove the check.
@43081j 43081j merged commit f168317 into main Jun 23, 2024
3 checks passed
@43081j 43081j deleted the ptests branch June 23, 2024 12:30
43081j added a commit that referenced this pull request Jun 23, 2024
When using index nesting, the parse loop visits `[` and computes keys
_only if_ we didn't just pass a `]`.

This is to capture the start of such a key. For example, `foo[bar][baz]`
would result in the only occurrence of this being `foo[`.

Since a syntactically valid indexed key should only have one of these
(at the start), `lastKey` should always be `undefined` at that point. So
we can remove the check.
43081j added a commit that referenced this pull request Jun 23, 2024
When using index nesting, the parse loop visits `[` and computes keys
_only if_ we didn't just pass a `]`.

This is to capture the start of such a key. For example, `foo[bar][baz]`
would result in the only occurrence of this being `foo[`.

Since a syntactically valid indexed key should only have one of these
(at the start), `lastKey` should always be `undefined` at that point. So
we can remove the check.
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.

2 participants