Fix spread operator lexing in records#15023
Merged
132ikl merged 3 commits intonushell:mainfrom Feb 11, 2025
Merged
Conversation
When parsing {...{}, ...{}, a: 1}, the "a:" would be considered one
token
blindFS
reviewed
Feb 6, 2025
Member
|
lgtm, thanks! |
Member
|
This seems to introduce a memory leak #15243 e.g. |
Member
Author
|
Whoops, good catch. #15246 should fix it. |
sholderbach
pushed a commit
that referenced
this pull request
Mar 5, 2025
Fixes #15243 # Description As noted in #15243, a record with more characters after it (e.g., `{a:b}/`) will cause an OOM due to an infinite loop, introduced by #15023. This happens because the entire string `{a:b}/` is lexed as one token and passed to `parse_record`, where it repeatedly lexes until it hits the closing `}`. This PR detects such extra characters and reports an error. # User-Facing Changes `{a:b}/` and other such constructions will no longer cause infinite loops. Before #15023, you would've seen an "Unclosed delimiter" error message, but this PR changes that to "Invalid characters." ``` Error: nu::parser::extra_token_after_closing_delimiter × Invalid characters after closing delimiter ╭─[entry #5:1:7] 1 │ {a:b}/ · ┬ · ╰── invalid characters ╰──── help: Try removing them. ``` # Tests + Formatting # After Submitting
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.
Description
Zyphys found that when parsing
{...{}, ...{}, a: 1}, thea:would be considered one token, leading to a parse error (Discord message). This PR fixes that.What would happen is that while getting tokens, the following would happen in a loop:
:as a special character (so we get the next field key and a colon token):as a special character (so we get the next value)I didn't update this when I added the spread operator. With
{...{}, ...{}, a: 1}, the first two tokens would be...{}and...{}, and the next token would bea:. This PR changes this loop to first get a single token, check if it's spreading a record, and move on if so.Alternatives considered:
:as a special character when getting the value too. This would simplify the loop greatly, but would mean you can't use colons in values.User-Facing Changes
Nothing new