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

syntax: do not require peeking two bytes after echo * #895

Merged
merged 1 commit into from
Jul 3, 2022

Conversation

mvdan
Copy link
Owner

@mvdan mvdan commented Jul 3, 2022

(see commit message)

Fixes #835.

@mvdan mvdan requested a review from riacataquian July 3, 2022 16:17
@mvdan
Copy link
Owner Author

mvdan commented Jul 3, 2022

cc @theclapp @prologic

The lexer wants to know if literal characters like `*` or `@` are
followed by `(`, because then they would be an extended globbing
expression like `@(pattern-list)`.

However, the current implementation first peeked for the bytes `()`,
to detect function declarations like `@() { ... }`.
Unfortunately, this caused interactive shells to hang on `echo *`
followed by a newline, as a newline is a single character.

To work around the problem, only peek `()` if we first peek `(`.

Moreover, the logic to call Parser.fill in Parser.peekBytes seems wrong.
The conditional definitely needs to use len(s), as that is the number of
bytes we want to look for. The new logic seems clearly better; we call
Parser.fill when p.bs contains fewer remaining bytes than len(s).

Note that we no longer loop on that logic, because we have zero tests
exercising that edge case, and I am slightly worried about endless loops
until we properly test those edge cases.

Fixes #835.
@mvdan mvdan changed the title syntax: do not require peeking two bytes afterecho * syntax: do not require peeking two bytes after echo * Jul 3, 2022
@mvdan mvdan force-pushed the peekbytes-hang branch from 64dd233 to 8542db7 Compare July 3, 2022 16:20
@mvdan
Copy link
Owner Author

mvdan commented Jul 3, 2022

Thanks for the quick reviews!

@mvdan mvdan merged commit 794dc6f into master Jul 3, 2022
@mvdan mvdan deleted the peekbytes-hang branch July 3, 2022 17:32
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.

cmd/gosh: echo * in interactive mode requires further input
3 participants