Skip to content

Commit

Permalink
[ShellScript] Fix indented HEREDOC termination (#3810)
Browse files Browse the repository at this point in the history
* [ShellScript] Fix indented HEREDOC termination

Fixes #3808

This commit restricts HEREDOC end tag indentation to `\t`.

If any other whitespace is found, a HEREDOC end tag does not match.

* [ShellScript] Add tests with mixed indentation
  • Loading branch information
deathaxe authored Jul 19, 2023
1 parent 7e58014 commit 74c43d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions ShellScript/Bash.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1371,11 +1371,11 @@ contexts:
- meta_scope: meta.string.heredoc.shell
- meta_content_scope: string.unquoted.heredoc.shell
- include: heredocs-body-common-with-expansion
- match: ^\s*(\3)$ # the third capture from redirections-here-document
- match: ^\t*(\3)$ # the third capture from redirections-here-document
captures:
1: meta.tag.heredoc.shell entity.name.tag.heredoc.shell
pop: 1
- match: ^\s*\3(\s+)\n # the third capture from redirections-here-document
- match: ^\t*\3(\s+)\n # the third capture from redirections-here-document
captures:
1: invalid.illegal.unexpected-whitespace.shell
# rather not pop, but sublime throws an error otherwise.
Expand Down Expand Up @@ -1404,11 +1404,11 @@ contexts:
heredocs-body-allow-tabs-no-expansion:
- meta_scope: meta.string.heredoc.shell
- meta_content_scope: string.unquoted.heredoc.shell
- match: ^\s*(\5)$ # the fourth capture from redirections-here-document
- match: ^\t*(\5)$ # the fourth capture from redirections-here-document
captures:
1: meta.tag.heredoc.shell entity.name.tag.heredoc.shell
pop: 1
- match: ^\s*\5(\s+)\n # the fourth capture from redirections-here-document
- match: ^\t*\5(\s+)\n # the fourth capture from redirections-here-document
captures:
1: invalid.illegal.unexpected-whitespace.shell
# rather not pop, but sublime throws an error otherwise.
Expand Down
26 changes: 16 additions & 10 deletions ShellScript/test/syntax_test_bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5806,10 +5806,10 @@ cat <<- INDENTED
say what now ${foo}
# ^^^^^^^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell string.unquoted.heredoc.shell - meta.interpolation
# ^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell meta.interpolation.parameter.shell - string
INDENTED
#^ meta.function-call.arguments.shell meta.string.heredoc.shell - meta.tag
# ^^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell meta.tag.heredoc.shell entity.name.tag.heredoc.shell
# ^ - meta.function-call - meta.string - meta.tag - entity
INDENTED
# <- meta.function-call.arguments.shell meta.string.heredoc.shell - meta.tag
#^^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell meta.tag.heredoc.shell entity.name.tag.heredoc.shell
# ^ - meta.function-call - meta.string - meta.tag - entity

cat <<- 'indented_without_expansions'
#^^^^^^^^ - meta.string - meta.tag
Expand All @@ -5822,10 +5822,10 @@ cat <<- 'indented_without_expansions'
${foo}
#^^^^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell string.unquoted.heredoc.shell - meta.interpolation
# ^^^ - variable.other
indented_without_expansions
#^^^ meta.function-call.arguments.shell meta.string.heredoc.shell - meta.tag
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell meta.tag.heredoc.shell entity.name.tag.heredoc.shell
# ^ - meta.function-call - meta.string - meta.tag - entity
indented_without_expansions
#^ meta.function-call.arguments.shell meta.string.heredoc.shell - meta.tag
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell meta.tag.heredoc.shell entity.name.tag.heredoc.shell
# ^ - meta.function-call - meta.string - meta.tag - entity

variable=$(cat <<SETVAR
This variable
Expand All @@ -5846,7 +5846,7 @@ cat <<- "FOO"
no \"escape\'\$ and $expansion
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.heredoc.shell - meta.interpolation
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.heredoc.shell - constant - keyword - variable
FOO
FOO
# ^^^ meta.function-call.arguments.shell meta.string.heredoc.shell meta.tag.heredoc.shell entity.name.tag.heredoc.shell
# ^ - meta.function-call - meta.string - meta.tag - entity

Expand All @@ -5861,7 +5861,13 @@ cat <<- \FOO
no \"escape\'\$ and $expansion
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.heredoc.shell - meta.interpolation
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.heredoc.shell - constant - keyword - variable
FOO
FOO
#^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell string.unquoted.heredoc.shell
FOO
#^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell string.unquoted.heredoc.shell
FOO
#^^^^^^^ meta.function-call.arguments.shell meta.string.heredoc.shell string.unquoted.heredoc.shell
FOO
# ^^^ meta.function-call.arguments.shell meta.string.heredoc.shell meta.tag.heredoc.shell entity.name.tag.heredoc.shell
# ^ - meta.function-call - meta.string - meta.tag - entity

Expand Down

0 comments on commit 74c43d2

Please sign in to comment.