You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated shebang & extention regex to be safer & match valid shellcheck shells
* `sh`
* `ash`
* `dash`
* `bash`
* `bats`
* `ksh`
[src](https://github.com/koalaman/shellcheck/blob/c2a15ce8e906ae6a12bcbe32eac7ac586fbcb59b/src/ShellCheck/Parser.hs#L3186-L3193)
---
Shebang regex:
Was: `'^#!.*sh'`
Now: `'^#!\(/\|/.*/\|/.* \)\(\(ba\|da\|k\|a\)*sh\|bats\)$'`
Test cases:
https://pastebin.com/BKB92wx2
Previous regex matched a lot of invalid shebangs & missed the 6 valid `bats` shebangs.
Current regex matches just the 6 correct shebangs from each valid shell.
There are probably some cases that I can't think of but it's a lot safer than the existing one.
A compromise would be something like: `'^#!/.*\(\(ba\|da\|k\|a\)*sh\|bats\)$'`
It matches the `zsh` `fish` and extra characters + valid shell ones but they're all at least valid.
---
File ending regex:
Was: `\.sh$|bash$`
Now: `.+\.(sh|bash|dash|ksh|ash|bats)$`
Test cases:
https://pastebin.com/JRJg8N13
Testing script:
```
test() {
if [[ "$1" =~ .+\.(sh|bash|dash|ksh|ash|bats)$ ]]; then
echo "match - $1"
else
echo "not match - $1"
fi
}
while IFS= read -r FILE; do
if [[ "$FILE" != "" ]]; then
test "$FILE"
fi
done <<EOF
TEST CASES HERE
EOF
```
Previous regex would match `.sh` `bash` and miss `file.ksh` `file.dash` `file.ash` `file.bats`
Current regex only matches the 3 normal file names + also matches just `.sh` `.bash` etc, which are very unusual but valid file names.
There's no extra checking for slashes etc because file names & escapes could confuse things, just the extension should be enough.
0 commit comments