Use options.Encoder when serializing dictionary keys and property names#40787
Use options.Encoder when serializing dictionary keys and property names#40787steveharter merged 1 commit intodotnet:masterfrom
Conversation
|
|
||
| private static readonly JsonEncodedText _keyName = JsonEncodedText.Encode(KeyName); | ||
| private static readonly JsonEncodedText _valueName = JsonEncodedText.Encode(ValueName); | ||
| // "encoder: null" is used since the literal values of "Key" and "Value" should not normally be escaped |
There was a problem hiding this comment.
Need to verify that this assumption is OK; without this assumption performance would suffer since the values could no longer be cached (at least can't be cached like below).
b5c148b to
778a3eb
Compare
2d9c960 to
777d576
Compare
| [Fact] | ||
| public static void DeserializePathForObjectFails() | ||
| { | ||
| const string GoodJson = "{\"Property\u04671\":1}"; |
There was a problem hiding this comment.
Interesting. This is the same issue as #40793 (comment) where GitHub gets tripped up by const strings containing characters written out in their "escaped" format, where it starts to consider this as invalid C# (even though it isn't). Note, the string keyword isn't being syntax-highlighted correctly either.
Looks like it's caused by the C# property names that contain escaped characters (from the above class definition ClassWithUnicodePropertyName - line 163 Property\u04671 ), which is throwing off all subsequent highlighting/C# validation up until this semi-colon on line 169.
|
Marking this a breaking since its an observable behavior diff. Let's make sure to document this change. |
Did we document this change somewhere? |
…es (dotnet/corefx#40787) Commit migrated from dotnet/corefx@7829d4a
Addresses https://github.com/dotnet/corefx/issues/40704 for master.
These locations were not escaped using the custom encoder specified on
options.Encoder:JsonException.Path(which is a property\dictionary path to an error)However all values (property, dictionary, etc) correctly used the custom escaper.
This may be ported to 3.0 pending feedback\priority.