diff --git a/components/prism-shell-session.js b/components/prism-shell-session.js index 652de04624..1b67ed76cf 100644 --- a/components/prism-shell-session.js +++ b/components/prism-shell-session.js @@ -33,7 +33,7 @@ // shell symbol /[$#%](?=\s)/.source + // bash command - /(?:[^\\\r\n'"<$]|\\(?:[^\r]|\r\n?)|\$(?!')|<>)+/.source.replace(/<>/g, function () { return strings; }), + /(?:[^\\\r\n \t'"<$]|[ \t](?:(?!#)|#.*$)|\\(?:[^\r]|\r\n?)|\$(?!')|<(?!<)|<>)+/.source.replace(/<>/g, function () { return strings; }), 'm' ), greedy: true, diff --git a/components/prism-shell-session.min.js b/components/prism-shell-session.min.js index e9c36cf35f..74810323c7 100644 --- a/components/prism-shell-session.min.js +++ b/components/prism-shell-session.min.js @@ -1 +1 @@ -!function(s){var n=['"(?:\\\\[^]|\\$\\([^)]+\\)|\\$(?!\\()|`[^`]+`|[^"\\\\`$])*"',"'[^']*'","\\$'(?:[^'\\\\]|\\\\[^])*'","<<-?\\s*([\"']?)(\\w+)\\1\\s[^]*?[\r\n]\\2"].join("|");s.languages["shell-session"]={command:{pattern:RegExp('^(?:[^\\s@:$#%*!/\\\\]+@[^\r\n@:$#%*!/\\\\]+(?::[^\0-\\x1F$#%*?"<>:;|]+)?|[/~.][^\0-\\x1F$#%*?"<>@:;|]*)?[$#%](?=\\s)'+"(?:[^\\\\\r\n'\"<$]|\\\\(?:[^\r]|\r\n?)|\\$(?!')|<>)+".replace(/<>/g,function(){return n}),"m"),greedy:!0,inside:{info:{pattern:/^[^#$%]+/,alias:"punctuation",inside:{user:/^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,punctuation:/:/,path:/[\s\S]+/}},bash:{pattern:/(^[$#%]\s*)\S[\s\S]*/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#%]/,alias:"important"}}},output:/.(?:.*(?:[\r\n]|.$))*/},s.languages["sh-session"]=s.languages.shellsession=s.languages["shell-session"]}(Prism); \ No newline at end of file +!function(s){var n=['"(?:\\\\[^]|\\$\\([^)]+\\)|\\$(?!\\()|`[^`]+`|[^"\\\\`$])*"',"'[^']*'","\\$'(?:[^'\\\\]|\\\\[^])*'","<<-?\\s*([\"']?)(\\w+)\\1\\s[^]*?[\r\n]\\2"].join("|");s.languages["shell-session"]={command:{pattern:RegExp('^(?:[^\\s@:$#%*!/\\\\]+@[^\r\n@:$#%*!/\\\\]+(?::[^\0-\\x1F$#%*?"<>:;|]+)?|[/~.][^\0-\\x1F$#%*?"<>@:;|]*)?[$#%](?=\\s)'+"(?:[^\\\\\r\n \t'\"<$]|[ \t](?:(?!#)|#.*$)|\\\\(?:[^\r]|\r\n?)|\\$(?!')|<(?!<)|<>)+".replace(/<>/g,function(){return n}),"m"),greedy:!0,inside:{info:{pattern:/^[^#$%]+/,alias:"punctuation",inside:{user:/^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,punctuation:/:/,path:/[\s\S]+/}},bash:{pattern:/(^[$#%]\s*)\S[\s\S]*/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#%]/,alias:"important"}}},output:/.(?:.*(?:[\r\n]|.$))*/},s.languages["sh-session"]=s.languages.shellsession=s.languages["shell-session"]}(Prism); \ No newline at end of file diff --git a/tests/languages/shell-session/command_string_feature.test b/tests/languages/shell-session/command_string_feature.test index 854314b8bb..930d0b62ca 100644 --- a/tests/languages/shell-session/command_string_feature.test +++ b/tests/languages/shell-session/command_string_feature.test @@ -21,6 +21,9 @@ $ cat << "EOF" > /etc/ipsec.secrets # : RSA vpn-server-b.key EOF +$ LC_ALL=C tr -cd 'a-zA-Z0-9_-;:!?.@\\*/#%$' < /dev/random | head -c 8 +y_#!$U48 + ---------------------------------------------------- [ @@ -64,10 +67,10 @@ EOF ["builtin", "echo"], ["punctuation", "\\"], "'a ", - ["comment", "# "] + ["comment", "# '"] ]] ]], - ["output", "'\r\n\r\n"], + ["command", [ ["shell-symbol", "$"], ["bash", [ @@ -83,7 +86,28 @@ EOF "\r\n: RSA vpn-server-a.key\r\n# : RSA vpn-server-b.key\r\nEOF" ]] ]] - ]] + ]], + + ["command", [ + ["shell-symbol", "$"], + ["bash", [ + ["assign-left", [ + ["environment", "LC_ALL"] + ]], + ["operator", ["="]], + "C ", + ["function", "tr"], + " -cd ", + ["string", "'a-zA-Z0-9_-;:!?.@\\\\*/#%$'"], + ["operator", ["<"]], + " /dev/random ", + ["operator", ["|"]], + ["function", "head"], + " -c ", + ["number", "8"] + ]] + ]], + ["output", "y_#!$U48"] ] ----------------------------------------------------