You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConvertTo-Json string escaped handling differs between PS and PSCore #7693
>$PSVersionTable
Name Value
---------
PSVersion 6.0.4
PSEdition Core
GitCommitId v6.0.4
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
This would appear to be because the StringEscapeHandling setting is set to Default in
If the StringEscapeHandling setting is set to [Newtonsoft.Json.StringEscapeHandling]::EscapeHtml then the JSON string that is generated matches what is returned by Windows PowerShell.
This has been the behavior since we changed to using NewtonSoft.JSON from the .NET Framework JSON serializer and would be a breaking change to change it back. mkht's suggestion to add a parameter would work and give more flexibility to the user. However, are there other settings that should be exposed via the cmdlet?
Confirmed NewtonSoft's reference.
I think that there is no other setting that needs to be exposed.
Other handling settings such as DateFormatHandling can be replaced by formatting the properties of the object to be passed in advance.
If you are adding parameters for escape handling, it will be necessary to discuss how to do the default value.
I think it should be [Newtonsoft.Json.StringEscapeHandling]::EscapeHtml. That's because JSON standard requires that quotation marks must be escaped. However, to avoid destructive changes, it should be [Newtonsoft.Json.StringEscapeHandling]::Default.
Latest JSON standard (RFC 8259) requires that the QUOTATION MARK (U+0022) must be escaped.
But, other quotation marks such as RIGHT SINGLE QUOTATION MARK (U+2019) or APOSTROPHE (U+0027) is not required to be.
Now, I think that the default setting should be [Newtonsoft.Json.StringEscapeHandling]::Default.
All Unicode characters may be placed within the quotation marks, except for the characters that MUST be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).
@PowerShell/powershell-committee reviewed this and agrees that Default should stay as default and we should expose -EscapeHandling as an optional parameter.
Activity
iSazonov commentedon Sep 3, 2018
Mark Kraus (@markekraus) Please look the Issue.
Is this a regression and should be fixed before 6.1.0 GA?
/cc Steve Lee (@SteveL-MSFT)
mkht commentedon Sep 5, 2018
Is not it a destructive change to change this behavior?
How about add parameter to change behavior like below ?
SteveL-MSFT commentedon Sep 5, 2018
This has been the behavior since we changed to using NewtonSoft.JSON from the .NET Framework JSON serializer and would be a breaking change to change it back. mkht's suggestion to add a parameter would work and give more flexibility to the user. However, are there other settings that should be exposed via the cmdlet?
mkht commentedon Sep 6, 2018
Confirmed NewtonSoft's reference.
I think that there is no other setting that needs to be exposed.
Other handling settings such as
DateFormatHandlingcan be replaced by formatting the properties of the object to be passed in advance.If you are adding parameters for escape handling, it will be necessary to discuss how to do the default value.
I think it should be
[Newtonsoft.Json.StringEscapeHandling]::EscapeHtml. That's because JSON standard requires that quotation marks must be escaped. However, to avoid destructive changes, it should be[Newtonsoft.Json.StringEscapeHandling]::Default.mkht commentedon Sep 6, 2018
Sorry, I had a misunderstanding.
Latest JSON standard (RFC 8259) requires that the
QUOTATION MARK (U+0022)must be escaped.But, other quotation marks such as
RIGHT SINGLE QUOTATION MARK (U+2019)orAPOSTROPHE (U+0027)is not required to be.Now, I think that the default setting should be
[Newtonsoft.Json.StringEscapeHandling]::Default.https://tools.ietf.org/rfc/rfc8259.txt
SteveL-MSFT commentedon Sep 12, 2018
@PowerShell/powershell-committee reviewed this and agrees that
Defaultshould stay as default and we should expose-EscapeHandlingas an optional parameter.