From 74c43d2261024008fd4fae2e7abc8d154f7d5baf Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 19 Jul 2023 10:58:14 +0200 Subject: [PATCH] [ShellScript] Fix indented HEREDOC termination (#3810) * [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 --- ShellScript/Bash.sublime-syntax | 8 ++++---- ShellScript/test/syntax_test_bash.sh | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ShellScript/Bash.sublime-syntax b/ShellScript/Bash.sublime-syntax index 6b477b5d84..7c3d582324 100644 --- a/ShellScript/Bash.sublime-syntax +++ b/ShellScript/Bash.sublime-syntax @@ -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. @@ -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. diff --git a/ShellScript/test/syntax_test_bash.sh b/ShellScript/test/syntax_test_bash.sh index 1faef04acc..5031caf07b 100755 --- a/ShellScript/test/syntax_test_bash.sh +++ b/ShellScript/test/syntax_test_bash.sh @@ -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 @@ -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 <