Skip to content

Commit

Permalink
Powershell: fix string escape issue
Browse files Browse the repository at this point in the history
Powershell use ` instead of \ to escape string. Current implement
ignores all code after something like "\".
ref: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters?view=powershell-7.3
  • Loading branch information
iaalm committed Mar 9, 2023
1 parent bd568be commit bca2e86
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Units/parser-powershell.r/simple-powershell.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ ErrorActionPreference input.ps1 /^$ErrorActionPreference = "Stop"$/;" v
Settings input.ps1 /^$Global:Settings = $null$/;" v
ALocalVar input.ps1 /^$Local:ALocalVar = $null$/;" v
BasePath input.ps1 /^$BasePath = split-path -parent $Global:MyInvocation.InvocationName$/;" v
cDrive input.ps1 /^$cDrive="C:\\"$/;" v
nextLine input.ps1 /^$nextLine="`n"$/;" v
backtick input.ps1 /^$backtick='`'$/;" v
Read-Configuration-File input.ps1 /^FUNCTION Read-Configuration-File() {$/;" f signature:()
LogMessageOK input.ps1 /^Function LogMessageOK()$/;" f signature:()
LogMessage input.ps1 /^function LogMessage() {$/;" f signature:()
Expand Down
4 changes: 4 additions & 0 deletions Units/parser-powershell.r/simple-powershell.d/input.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ $Local:ALocalVar = $null
# a usual variable
$BasePath = split-path -parent $Global:MyInvocation.InvocationName

# different type of escape in string
$cDrive="C:\"
$nextLine="`n"
$backtick='`'

FUNCTION Read-Configuration-File() {
$Hostname = [System.Environment]::MachineName
Expand Down
2 changes: 1 addition & 1 deletion parsers/powershell.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static void parseString (vString *const string, const int delimiter)
{
int c = getcFromInputFile ();

if (c == '\\' && (c = getcFromInputFile ()) != EOF)
if (delimiter == '"' && c == '`' && (c = getcFromInputFile ()) != EOF)
vStringPut (string, c);
else if (c == EOF || c == delimiter)
break;
Expand Down

0 comments on commit bca2e86

Please sign in to comment.