Skip to content

Commit

Permalink
Powershell: Allow for one level of nesting in expressions inside stri…
Browse files Browse the repository at this point in the history
…ngs. Fix #1407
  • Loading branch information
Golmote committed Apr 27, 2018
1 parent 7bc9a4a commit 9272d6f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 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: /(^|[^`])\$\(.*?\)/,
// Allow for one level of nesting
pattern: /(^|[^`])\$\((?:\$\(.*?\)|(?!\$\()[^\r\n)])*\)/,
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.

43 changes: 43 additions & 0 deletions tests/languages/powershell/issue1407.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
While($true){
Write-Output "$($($InFiles | Where-Object {$_.ToCopy -eq 0}).count)"
}

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

[
["keyword", "While"],
["punctuation", "("],
["boolean", "$true"],
["punctuation", ")"],
["punctuation", "{"],
["function", "Write-Output"],
["string", [
"\"",
["function", [
"$",
["punctuation", "("],
"$",
["punctuation", "("],
["variable", "$InFiles"],
["punctuation", "|"],
["function", "Where-Object"],
["punctuation", "{"],
["variable", "$_"],
["punctuation", "."],
"ToCopy ",
["operator", "-eq"],
" 0",
["punctuation", "}"],
["punctuation", ")"],
["punctuation", "."],
"count",
["punctuation", ")"]
]],
"\""
]],
["punctuation", "}"]
]

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

Checks for nested expressions in strings.
14 changes: 14 additions & 0 deletions tests/languages/powershell/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ an empty '' string
"has $interpolated <# variables #>"
"$($expression)"
"`$(escaped expression)"
"$($($exp))"

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

Expand Down Expand Up @@ -56,6 +57,19 @@ an empty '' string
]],
["string", [
"\"`$(escaped expression)\""
]],
["string", [
"\"",
["function", [
"$",
["punctuation", "("],
"$",
["punctuation", "("],
["variable", "$exp"],
["punctuation", ")"],
["punctuation", ")"]
]],
"\""
]]
]

Expand Down

0 comments on commit 9272d6f

Please sign in to comment.