Skip to content

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

Open

Description

@holmanb

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

Activity

  1. holmanb commented on Mar 12, 2024

    @holmanb
    Author

    @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.

  2. holmanb commented on Apr 24, 2024

    @holmanb
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions