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

Parsing Broken: Remove smallest pattern with nested expansion is broken #254

Open
holmanb opened this issue Feb 16, 2024 · 2 comments
Open

Comments

@holmanb
Copy link

holmanb commented Feb 16, 2024

The grammar doesn't appear to handle quoted expansion inside of ${} when removing the smallest suffix pattern via %.

This is broken: "${1%"$2"*}", this is not: "${1%$2*}". The broken behavior only appears when followed by a double quoted string.

I've tried to reduce the issue as much as possible to ease debugging. The following demonstrates the issue:

#!/bin/sh
remove_smallest_1(){
	echo "${1%$2*}"
}
remove_smallest_1 deleted d
remove_smallest_2(){
	echo "${1%"$2"*}"
}
remove_smallest_2 deleted d
echo "broke"

Note: not quoting the expansion within "${}" is warned about by shellcheck SC2295, which is how I discovered this issue.

Using treesitter with neovim:

Screenshot from 2024-02-16 10-29-53

@holmanb
Copy link
Author

holmanb commented Mar 12, 2024

@amaanq I'm not familiar with this codebase. If I were to try to start looking for the source of this issue, where would I start?

It makes files that contain this syntax unusable.

@holmanb
Copy link
Author

holmanb commented Apr 24, 2024

@amaanq would you say that this is a duplicate of #214?

but I'm pretty sure statefulness would be needed for stuff within quotes within escaped quotes - that's just too much (the main issue is the $)

This sounds like a similar class of problem. I'm happy to close if you'd rather. I've just silenced shellcheck on this line in the codebase I discovered this in to use the syntax that treesitter understands.

That said, shellcheck actually recommends this syntax, so more reports of this type of issue might crop up.

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

No branches or pull requests

1 participant