ps/Modules/Alkami.PowerShell.Common/Public/ConvertTo-SafeTeamCityMessage.ps1

31 lines
793 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
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)
}