Skip to content

Glob pattern with quoted string containing spaces fails to parse in [[ ]] #321

@Whoaa512

Description

@Whoaa512

Version

v0.25.1 (commit a06c2e4)

Minimal reproduction

This parses correctly (no spaces in quoted string):

if [[ "${tmp}" = *"AB"* ]]; then
  echo "ok"
fi

This fails (space in quoted string):

if [[ "${tmp}" = *"A B"* ]]; then
  echo "ok"
fi

Expected behavior

Both should parse as a valid if_statement with a test_command containing a binary_expression.

Actual behavior

The second example produces an ERROR node spanning the entire if statement:

(program [0, 0] - [3, 0]
  (ERROR [0, 0] - [2, 2]
    (ERROR [0, 6] - [0, 20]

Real-world example

This pattern is common for checking certificate contents:

if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then
  # ...
fi

The space in "BEGIN CERTIFICATE" triggers the parse failure, causing syntax highlighting to break for everything inside the function.

Notes

  • Without glob stars, "A B" parses fine: [[ "${tmp}" = "A B" ]]
  • Without spaces, glob pattern parses fine: [[ "${tmp}" = *"AB"* ]]
  • The combination *"string with space"* fails

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