ps/Modules/Alkami.PowerShell.Common/Public/ConvertTo-SafeTeamCityMessage.ps1
2023-05-30 22:51:22 -07:00

31 lines
793 B
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}