Skip to content

Commit

Permalink
Powershell: Add lookbehind to fix function interpolation inside strin…
Browse files Browse the repository at this point in the history
…gs. Fix #1361
  • Loading branch information
Golmote committed Mar 20, 2018
1 parent a5331a6 commit d2c026e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion components/prism-powershell.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Prism.languages.powershell = {
greedy: true,
inside: {
'function': {
pattern: /[^`]\$\(.*?\)/,
pattern: /(^|[^`])\$\(.*?\)/,
lookbehind: true,
// Populated at end of file
inside: {}
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-powershell.min.js

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

33 changes: 24 additions & 9 deletions tests/languages/powershell/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,54 @@ an empty '' string
'can''t'
"a simple #comment string"
"has $interpolated <# variables #>"
"$($expression)"
"`$(escaped expression)"

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

[
["string", ["\"a simple string\""]],
["string", [
"\"has ",["variable", "$interpolated"]," variables\""]
],
"\"has ", ["variable", "$interpolated"], " variables\""
]],
["string", [
"\"has",
"\"has ",
[
"function",
[
" $",
"$",
["punctuation", "("],
["variable", "$nesting"],
["operator", "-and"],
["string", "'interpolation'"],
["punctuation", ")"]
]
],
"\""]
],
"\""
]],
["string", ["\"string `\"with`\" escaping\""]],
["string", "'non-interpolated $string'"],
["string", "'also ''with'' escaping'"],
["string", "'''twas also escaped'"],
"\r\nan empty ",["string", "''"], " string\r\n",
"\r\nan empty ", ["string", "''"], " string\r\n",
["string", "'can''t'"],
["string", ["\"a simple #comment string\""]],
["string", [
"\"has ",["variable", "$interpolated"]," <# variables #>\""]
]
"\"has ", ["variable", "$interpolated"], " <# variables #>\""
]],
["string", [
"\"",
["function", [
"$",
["punctuation", "("],
["variable", "$expression"],
["punctuation", ")"]
]],
"\""
]],
["string", [
"\"`$(escaped expression)\""
]]
]

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

0 comments on commit d2c026e

Please sign in to comment.