Skip to content

Commit 34f9661

Browse files
rachelxj-msXuejun Li
andauthored
ReFix Set-AzPolicySetDefinition InternalServerError when the initiative is too large [#20238] (#20399)
* Fixed issue introduced in previous fix for `Set-AzPolicySetDefinition` InternalServerError when the initiative is too large [#20238], which will remove space in value. * avoid unexpected exception in deserilize json string Co-authored-by: Xuejun Li <[email protected]>
1 parent c283104 commit 34f9661

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Resources/ResourceManager/RestClients/ResourceManagerRestClientBase.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.RestClients
1818
using System.Linq;
1919
using System.Net.Http;
2020
using System.Text;
21-
using System.Text.RegularExpressions;
2221
using System.Threading;
2322
using System.Threading.Tasks;
2423
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
@@ -165,7 +164,18 @@ protected async Task<HttpResponseMessage> SendRequestAsync(
165164
{
166165
var contentString = content == null ? string.Empty : content.ToString();
167166
// minify JOSN payload to avoid payload too large error
168-
contentString = Regex.Replace(contentString, @"\r\n?|\n|\t| ", String.Empty);
167+
if (!string.IsNullOrEmpty(contentString))
168+
{
169+
try
170+
{
171+
var obj = JsonConvert.DeserializeObject(contentString);
172+
contentString = JsonConvert.SerializeObject(obj, Formatting.None);
173+
}
174+
catch
175+
{
176+
// leave contentString as it is
177+
}
178+
}
169179
using (var httpContent = new StringContent(content: contentString, encoding: Encoding.UTF8, mediaType: "application/json"))
170180
using (var request = new HttpRequestMessage(method: httpMethod, requestUri: requestUri) { Content = httpContent })
171181
{

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Fixed issue introduced in previous fix for `Set-AzPolicySetDefinition` InternalServerError when the initiative is too large [#20238], which will remove space in value.
2223

2324
## Version 6.5.0
2425
* Added cmdlet `Get-AzADOrganization`

0 commit comments

Comments
 (0)