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: parser hangs when a bracket isn't closed (#1005) #1029

Merged
merged 8 commits into from
Dec 29, 2024
Merged

Conversation

harrisbisset
Copy link
Contributor

If a bracket (curly or parentheses) isn't closed, the parser keeps reading until it is closed.
However, the parser NEVER checks if EOF is reached. So, the parser loops when EOF and there's a missing bracket.

Solution:

Check for EOF before handling anything else (could be elsewhere, but I think this makes the most sense).
If the parser is expecting nested functions, then it should return an error with the unclosed bracket.

Example:

Templ:

package example

templ Show() {
    @Exists(
}

Result:

(✗) Error [ error=failed to generate code for "path_here/example.templ": /path_here/example.templ parsing error: templ element: invalid go expression: unbalanced '(': line 3, col 5 ]
(✗) Command failed: generation completed with 1 errors

Closes #1005

@a-h
Copy link
Owner

a-h commented Dec 29, 2024

Thanks for your contribution, much appreciated.

@a-h a-h merged commit 9058914 into a-h:main Dec 29, 2024
4 checks passed
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.

Excessive CPU and memory usage caused by a wrong syntax (unclosed brackets)
3 participants