File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,4 +76,37 @@ function InvokeHelperTest_Invoke_MyCommand_WithParameters_WithMock {
7676 Assert-AreEqual - Expected ' fakeName' - Presented $result.login
7777 Assert-AreEqual - Expected 6666666 - Presented $result.id
7878
79+ }
80+
81+ function InvokeHelperTest_Invoke_MyCommand_WithDoubleQuotes {
82+ [CmdletBinding ()]
83+ param ()
84+
85+ $str = ' Hello "world"'
86+ $command = ' echo "{string}"'
87+
88+ # # Wrong call with no parameter formatting
89+
90+ # Arrange
91+ $param = @ {
92+ string = $str
93+ }
94+ # Act
95+ $result = Invoke-MyCommand - Command $command - Parameters $param
96+
97+ # Assert
98+ Assert-AreNotEqual - Expected $str - Presented $result
99+
100+ # Correct call with parameter formatting
101+
102+ # Arrange
103+ $param = @ {
104+ string = $str | ConvertTo-InvokeParameterString
105+ }
106+
107+ # Act
108+ $result = Invoke-MyCommand - Command $command - Parameters $param
109+
110+ # Assert
111+ Assert-AreEqual - Expected $str - Presented $result
79112}
Original file line number Diff line number Diff line change 1+
2+ # Invoke command use powershell calls to manage the dependencies
3+ # if a string contains double quotes, it will fail as it will confuse the string content with parameter values
4+ # so we need to escape the double quotes in the string to ensure the quotes that are part of the string value and not parameter boundaries
5+
6+ function ConvertTo-InvokeParameterString {
7+ param (
8+ [Parameter (ValueFromPipeline , Position = 0 )][string ]$InputString
9+ )
10+
11+ process {
12+
13+ if ([string ]::IsNullOrEmpty($InputString )) {
14+ return $InputString
15+ }
16+
17+ $OutputString = $InputString -replace ' "' , ' ""'
18+ return $OutputString
19+ }
20+ } Export-ModuleMember - Function ConvertTo-InvokeParameterString
You can’t perform that action at this time.
0 commit comments