Skip to content

Commit 7a751e0

Browse files
committed
add json escape support for text replacements
1 parent 7bb4512 commit 7a751e0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Modules/CIPPCore/Public/Get-CIPPTextReplacement.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function Get-CIPPTextReplacement {
1313
#>
1414
param (
1515
[string]$TenantFilter,
16-
$Text
16+
$Text,
17+
[switch]$EscapeForJson
1718
)
1819
if ($Text -isnot [string]) {
1920
return $Text
@@ -54,13 +55,21 @@ function Get-CIPPTextReplacement {
5455
$Vars = @{}
5556
if ($GlobalMap) {
5657
foreach ($Var in $GlobalMap) {
58+
if ($EscapeForJson.IsPresent) {
59+
# Escape quotes for JSON if not already escaped
60+
$Var.Value = $Var.Value -replace '(?<!\\)"', '\"'
61+
}
5762
$Vars[$Var.RowKey] = $Var.Value
5863
}
5964
}
6065
# Tenant Specific Variables
6166
$ReplaceMap = Get-CIPPAzDataTableEntity @ReplaceTable -Filter "PartitionKey eq '$CustomerId'"
6267
if ($ReplaceMap) {
6368
foreach ($Var in $ReplaceMap) {
69+
if ($EscapeForJson.IsPresent) {
70+
# Escape quotes for JSON if not already escaped
71+
$Var.Value = $Var.Value -replace '(?<!\\)"', '\"'
72+
}
6473
$Vars[$Var.RowKey] = $Var.Value
6574
}
6675
}

Modules/CIPPCore/Public/GraphHelper/New-GraphPOSTRequest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function New-GraphPOSTRequest ($uri, $tenantid, $body, $type, $scope, $AsApp, $N
2222
$contentType = 'application/json; charset=utf-8'
2323
}
2424
try {
25-
$body = Get-CIPPTextReplacement -TenantFilter $tenantid -Text $body
25+
$body = Get-CIPPTextReplacement -TenantFilter $tenantid -Text $body -EscapeForJson
2626
$ReturnedData = (Invoke-RestMethod -Uri $($uri) -Method $TYPE -Body $body -Headers $headers -ContentType $contentType -SkipHttpErrorCheck:$IgnoreErrors -ResponseHeadersVariable responseHeaders)
2727
} catch {
2828
$Message = if ($_.ErrorDetails.Message) {

0 commit comments

Comments
 (0)