31 lines
793 B
PowerShell
31 lines
793 B
PowerShell
|
function ConvertTo-SafeTeamCityMessage {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Converts strings to sanitized strings that are safe to use for TeamCity Service Messages.
|
|||
|
.EXAMPLE
|
|||
|
ConvertTo-SafeTeamCityMessage "I have a | pipe"
|
|||
|
will return "I have a || pipe"
|
|||
|
.INPUTS
|
|||
|
Input: String
|
|||
|
also can be null input
|
|||
|
.OUTPUTS
|
|||
|
Output: String
|
|||
|
#>
|
|||
|
param(
|
|||
|
[Parameter(Mandatory = $true)]
|
|||
|
[AllowEmptyString()]
|
|||
|
[string] $InputText
|
|||
|
)
|
|||
|
|
|||
|
$sanitizedText = $InputText
|
|||
|
$charactersToEscape = @( "|", "'", "’", "[", "]")
|
|||
|
foreach ($char in $charactersToEscape) {
|
|||
|
$sanitizedText = $sanitizedText.Replace($char, "|$char")
|
|||
|
}
|
|||
|
|
|||
|
$sanitizedText = $sanitizedText.Replace("`r", "|r")
|
|||
|
$sanitizedText = $sanitizedText.Replace("`n", "|n")
|
|||
|
|
|||
|
return ($sanitizedText)
|
|||
|
}
|