Skip to content

Commit

Permalink
Fix mocking commands with single quote in names
Browse files Browse the repository at this point in the history
BOM is required for PowerShell to properly recognize UTF-8 encoding.
  • Loading branch information
PetSerAl committed Feb 18, 2016
1 parent 6b51cc5 commit 7dcc6e5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Functions/Mock.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Mock {
function Mock {

<#
.SYNOPSIS
Expand Down Expand Up @@ -273,9 +273,16 @@ about_Mocking
}
}

$EscapeSingleQuotedStringContent =
if ($global:PSVersionTable.PSVersion.Major -ge 5) {
{ [System.Management.Automation.Language.CodeGeneration]::EscapeSingleQuotedStringContent($args[0]) }
} else {
{ $args[0] -replace "['‘’‚‛]", '$&$&' }
}

$newContent = & $SafeCommands['Get-Content'] function:\MockPrototype
$newContent = $newContent -replace '#FUNCTIONNAME#', $CommandName
$newContent = $newContent -replace '#MODULENAME#', $ModuleName
$newContent = $newContent -replace '#FUNCTIONNAME#', (& $EscapeSingleQuotedStringContent $CommandName)
$newContent = $newContent -replace '#MODULENAME#', (& $EscapeSingleQuotedStringContent $ModuleName)

$canCaptureArgs = 'true'
if ($contextInfo.Command.CommandType -eq 'Cmdlet' -or
Expand Down

0 comments on commit 7dcc6e5

Please sign in to comment.