Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in Bash strings #792

Merged
merged 1 commit into from
Oct 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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