diff --git a/src/Resources/ResourceManager/RestClients/ResourceManagerRestClientBase.cs b/src/Resources/ResourceManager/RestClients/ResourceManagerRestClientBase.cs index 5ef6a2df3568..5adcccc0eba5 100644 --- a/src/Resources/ResourceManager/RestClients/ResourceManagerRestClientBase.cs +++ b/src/Resources/ResourceManager/RestClients/ResourceManagerRestClientBase.cs @@ -18,7 +18,6 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.RestClients using System.Linq; using System.Net.Http; using System.Text; - using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components; @@ -165,7 +164,18 @@ protected async Task SendRequestAsync( { var contentString = content == null ? string.Empty : content.ToString(); // minify JOSN payload to avoid payload too large error - contentString = Regex.Replace(contentString, @"\r\n?|\n|\t| ", String.Empty); + if (!string.IsNullOrEmpty(contentString)) + { + try + { + var obj = JsonConvert.DeserializeObject(contentString); + contentString = JsonConvert.SerializeObject(obj, Formatting.None); + } + catch + { + // leave contentString as it is + } + } using (var httpContent = new StringContent(content: contentString, encoding: Encoding.UTF8, mediaType: "application/json")) using (var request = new HttpRequestMessage(method: httpMethod, requestUri: requestUri) { Content = httpContent }) { diff --git a/src/Resources/Resources/ChangeLog.md b/src/Resources/Resources/ChangeLog.md index 507fb7b251ba..b9035fef1d65 100644 --- a/src/Resources/Resources/ChangeLog.md +++ b/src/Resources/Resources/ChangeLog.md @@ -19,6 +19,7 @@ --> ## Upcoming Release +* Fixed issue introduced in previous fix for `Set-AzPolicySetDefinition` InternalServerError when the initiative is too large [#20238], which will remove space in value. ## Version 6.5.0 * Added cmdlet `Get-AzADOrganization`