Skip to content

Commit

Permalink
Merge pull request #792 from zeitgeist87/BashString
Browse files Browse the repository at this point in the history
Fix regression in Bash strings
  • Loading branch information
Golmote committed Oct 5, 2015
2 parents 7c7ab4e + 256c3e1 commit bd275c2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
10 changes: 4 additions & 6 deletions components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
lookbehind: true
},
'string': [
//Support for Here-Documents https://en.wikipedia.org/wiki/Here_document
{
pattern: /"(?:\\?[\s\S])*?"/g,
pattern: /((?:^|[^<])<<\s*)(?:"|')?(\w+?)(?:"|')?\s*\r?\n(?:[\s\S])*?\r?\n\2/g,
lookbehind: true,
inside: bashVars
},
// Single quote strings cannot have variables inside
/'(?:\\?[\s\S])*?'/g,
// Support for Here-Documents https://en.wikipedia.org/wiki/Here_document
{
pattern: /(<<\s*)(\w+?)\s*\r?\n(?:[\s\S])*?\r?\n\2/g,
lookbehind: true,
pattern: /("|')(?:\\?[\s\S])*?\1/g,
inside: bashVars
}
],
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions tests/languages/bash/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
bar"
'foo
bar'
"'foo'"
'"bar"'
"$@"
"${foo}"
<< STRING_END
Expand All @@ -16,16 +18,26 @@ STRING_END
foo $@
bar
EOF
<< 'EOF'
'single quoted string'
"double quoted string"
EOF
<< "EOF"
foo
bar
EOF

----------------------------------------------------

[
["string", ["\"\""]],
["string", "''"],
["string", ["''"]],
["string", ["\"foo\""]],
["string", "'foo'"],
["string", ["'foo'"]],
["string", ["\"foo\r\nbar\""]],
["string", "'foo\r\nbar'"],
["string", ["'foo\r\nbar'"]],
["string", ["\"'foo'\""]],
["string", ["'\"bar\"'"]],
["string", [
"\"", ["variable", "$@"], "\""
]],
Expand All @@ -37,7 +49,13 @@ EOF
["string", ["STRING_END\r\nfoo\r\nbar\r\nSTRING_END"]],
["operator", "<"],
["operator", "<"],
["string", ["EOF\r\nfoo ", ["variable", "$@"], "\r\nbar\r\nEOF"]]
["string", ["EOF\r\nfoo ", ["variable", "$@"], "\r\nbar\r\nEOF"]],
["operator", "<"],
["operator", "<"],
["string", ["'EOF'\r\n'single quoted string'\r\n\"double quoted string\"\r\nEOF"]],
["operator", "<"],
["operator", "<"],
["string", ["\"EOF\"\r\nfoo\r\nbar\r\nEOF"]]
]

----------------------------------------------------
Expand Down

0 comments on commit bd275c2

Please sign in to comment.