diff --git a/StoreBroker/Helpers.ps1 b/StoreBroker/Helpers.ps1 index 00afcf9f..199a00d6 100644 --- a/StoreBroker/Helpers.ps1 +++ b/StoreBroker/Helpers.ps1 @@ -321,57 +321,6 @@ function Get-SHA512Hash return [System.BitConverter]::ToString($sha512.ComputeHash($utf8.GetBytes($PlainText))) -replace '-', '' } -function Get-EscapedJsonValue -{ -<# - .SYNOPSIS - Escapes special characters within a string for use within a JSON value. - - .DESCRIPTION - Escapes special characters within a string for use within a JSON value. - - The Git repo for this module can be found here: http://aka.ms/StoreBroker - - .PARAMETER Value - The string that needs to be escaped - - .EXAMPLE - Get-EscapedJsonValue -Value 'This is my "quote". Look here: c:\windows\' - - Returns back the string 'This is my \"quote\". Look here: c:\\windows\\' - - .OUTPUTS - System.String - A string with special characters escaped for use within JSON. - - .NOTES - Normalizes newlines and carriage returns to always be \r\n. -#> - [CmdletBinding()] - param( - [Parameter( - Mandatory, - ValueFromPipeline)] - [AllowNull()] - [AllowEmptyString()] - [string] $Value - ) - - # The syntax of -replace is a bit confusing, so it's worth a note here. - # The first parameter is a regular expression match pattern. The second parameter is a replacement string. - # So, when we try to do "-replace '\\', '\\", that's matching a single backslash (which has to be - # escaped within the match regular expression as a double-backslash), and replacing it with a - # string containing literally two backslashes. - # (And as a reminder, PowerShell's escape character is actually the backtick (`) and not backslash (\).) - - # \, ", - $escaped = $Value -replace '\\', '\\' -replace '"', '\"' -replace '\t', '\t' - - # Now normalize actual CR's and LF's with their control codes. We'll ensure all variations are uniformly formatted as \r\n - $escaped = $escaped -replace '\r\n', '\r\n' -replace '\r', '\r\n' -replace '\n', '\r\n' - - return $escaped -} - function ConvertTo-Array { <# diff --git a/StoreBroker/PackageTool.ps1 b/StoreBroker/PackageTool.ps1 index f359c70f..b47990e7 100644 --- a/StoreBroker/PackageTool.ps1 +++ b/StoreBroker/PackageTool.ps1 @@ -125,16 +125,16 @@ function Get-StoreBrokerConfigFileContentForIapId $updated = $updated -replace '"lifetime": ".*",', "`"lifetime`": `"$($sub.lifetime)`"," $updated = $updated -replace '"contentType": ".*",', "`"contentType`": `"$($sub.contentType)`"," - $tag = Get-EscapedJsonValue -Value $sub.tag - $updated = $updated -replace '"tag": ""', "`"tag`": `"$tag`"" + $tag = ConvertTo-Json -InputObject ($sub.tag -replace '//', '\\') # Ensure // doesn't get stripped out as a comment later on. + $updated = $updated -replace '"tag": ""', "`"tag`": $tag" $keywords = $sub.keywords | ConvertTo-Json -Depth $script:jsonConversionDepth if ($null -eq $keywords) { $keywords = "[ ]" } $updated = $updated -replace '(\s+)"keywords": \[.*(\r|\n)+\s*\]', "`$1`"keywords`": $keywords" # NOTES FOR CERTIFICATION - $notesForCertification = Get-EscapedJsonValue -Value $sub.notesForCertification - $updated = $updated -replace '"notesForCertification": ""', "`"notesForCertification`": `"$notesForCertification`"" + $notesForCertification = ConvertTo-Json -InputObject ($sub.notesForCertification -replace '//', '\\') # Ensure // doesn't get stripped out as a comment later on. + $updated = $updated -replace '"notesForCertification": ""', "`"notesForCertification`": $notesForCertification" return $updated } @@ -361,8 +361,8 @@ function Get-StoreBrokerConfigFileContentForAppId } # NOTES FOR CERTIFICATION - $notesForCertification = Get-EscapedJsonValue -Value $sub.notesForCertification - $updated = $updated -replace '"notesForCertification": ""', "`"notesForCertification`": `"$notesForCertification`"" + $notesForCertification = ConvertTo-Json -InputObject ($sub.notesForCertification -replace '//', '\\') # Ensure // doesn't get stripped out as a comment later on. + $updated = $updated -replace '"notesForCertification": ""', "`"notesForCertification`": $notesForCertification" return $updated }