Skip to content

Commit 1bb5aa6

Browse files
authored
Merge pull request #3153 from microsoftgraph/3149-failure-response-from-update-mgapplication-with--web-switch-and-redirecturis-specified-since-version-2260
Ensures property values that have `/` are not modified to have them removed
2 parents b0bcddf + 43bea4b commit 1bb5aa6

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

tools/Custom/JsonExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static string RemoveDefaultNullProperties(this JToken token)
7979

8080
public static string ReplaceAndRemoveSlashes(this string body)
8181
{
82-
return body.Replace("/", "").Replace("\\", "").Replace("rn", "").Replace("\"{", "{").Replace("}\"", "}");
82+
return body.Replace("\\", "").Replace("rn", "").Replace("\"{", "{").Replace("}\"", "}");
8383
}
8484
}
8585
}

tools/Tests/JsonUtilitiesTest/JsonExtensionsTests.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace JsonUtilitiesTest;
22
using System;
3+
using System.Text.Json;
34
using Newtonsoft.Json.Linq;
45
using Xunit;
56
using NamespacePrefixPlaceholder.PowerShell.JsonUtilities;
@@ -144,6 +145,66 @@ public void RemoveDefaultNullProperties_ShouldRemoveDefaultNullValuesInJsonArray
144145
Assert.False(result[0].ToObject<JObject>().ContainsKey("email"));
145146

146147
}
148+
[Fact]
149+
public void ReplaceAndRemoveSlashes_Should_Preserve_Json_Property_Values()
150+
{
151+
// Arrange
152+
string inputJson = @"{
153+
""RedirectUris"": [""http://localhost/.auth/login/aad/callback""],
154+
""DirectoryPath"": ""/this/is/a/directory/and/should/not/be/removed""
155+
}";
156+
157+
string expectedJson = @"{
158+
""RedirectUris"": [""http://localhost/.auth/login/aad/callback""],
159+
""DirectoryPath"": ""/this/is/a/directory/and/should/not/be/removed""
160+
}";
161+
162+
// Act
163+
string result = inputJson.ReplaceAndRemoveSlashes();
164+
165+
// Assert
166+
Assert.Equal(NormalizeJson(expectedJson), NormalizeJson(result));
167+
}
168+
169+
[Fact]
170+
public void ReplaceAndRemoveSlashes_Should_Remove_Backslashes()
171+
{
172+
// Arrange
173+
string input = @"Some \random \slashes that \should be removed.";
174+
string expected = "Some random slashes that should be removed.";
175+
176+
// Act
177+
string result = input.ReplaceAndRemoveSlashes();
178+
179+
// Assert
180+
Assert.Equal(expected, result);
181+
}
182+
183+
[Fact]
184+
public void ReplaceAndRemoveSlashes_Should_Handle_Invalid_Json_Gracefully()
185+
{
186+
// Arrange
187+
string invalidJson = "{Invalid Json \\with /slashes}";
188+
189+
// Act
190+
string result = invalidJson.ReplaceAndRemoveSlashes();
191+
192+
// Assert
193+
Assert.DoesNotContain("\\", result);
194+
}
195+
196+
/// <summary>
197+
/// Normalizes JSON for comparison (removes formatting differences).
198+
/// </summary>
199+
private string NormalizeJson(string json)
200+
{
201+
using var doc = JsonDocument.Parse(json);
202+
return JsonSerializer.Serialize(doc.RootElement, new JsonSerializerOptions
203+
{
204+
WriteIndented = false,
205+
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
206+
});
207+
}
147208

148209

149210
}

0 commit comments

Comments
 (0)