Skip to content

Parsing error with extglob inside a pattern with some special prefixes #246

Open

Description

@folliehiyuki

An example with an asterisk at the start of the pattern:

if [[ "README.md" == *.@(md|mkd|markdown) ]]; then
    echo "This is a Markdown file"
fi

The corresponding node tree:

(if_statement) ; [1:1 - 3:2]
 condition: (test_command) ; [1:4 - 44]
  (binary_expression) ; [1:7 - 41]
   left: (string) ; [1:7 - 17]
    (string_content) ; [1:8 - 16]
   (ERROR) ; [1:22 - 24]
    (word) ; [1:22 - 24]
   right: (parenthesized_expression) ; [1:25 - 41]
    (binary_expression) ; [1:26 - 40]
     left: (binary_expression) ; [1:26 - 31]
      left: (word) ; [1:26 - 27]
      right: (word) ; [1:29 - 31]
     right: (word) ; [1:33 - 40]
 (command) ; [2:5 - 34]
  name: (command_name) ; [2:5 - 8]
   (word) ; [2:5 - 8]
  argument: (string) ; [2:10 - 34]
   (string_content) ; [2:11 - 33]

A few more examples that also produce errors:

# Start with a question mark
[[ "a.md" == ?.@(md|mkd) ]]

# Start with a dot
[[ ".md" == .@(md|mkd) ]]

# The pattern also have quoted string at the start
[[ "ab.md" == "ab".@(md|mkd) ]]

These are all valid Bash, according to https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html

Activity

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