-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-System.Text.Jsonjson-functionality-docMissing JSON specific functionality that needs documentingMissing JSON specific functionality that needs documenting
Milestone
Description
When writing an unescaped value like "jwt+secevent", the Utf8JsonWriter
is honoring the contract by not escaping the value, as illustrated in the following test:
[Fact]
public void JsonWriter_UnescapedValue()
{
var output = new FixedSizedBufferWriter(100);
var jsonUtf8 = new Utf8JsonWriter(output);
jsonUtf8.WriteStringValue("jwt+secevent", false);
jsonUtf8.Flush();
string actualStr = Encoding.UTF8.GetString(output.Formatted);
Assert.Equal(@"""jwt+secevent""", actualStr);
// actualStr == "jwt+secevent"
}
When writing an unescaped value, the Utf8JsonWriter
is not honoring the contract by escaping the value:
[Fact]
public void JsonWriter_UnescapedProperty()
{
var output = new FixedSizedBufferWriter(100);
var jsonUtf8 = new Utf8JsonWriter(output);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteString("unescaped", "jwt+secevent", false);
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
string actualStr = Encoding.UTF8.GetString(output.Formatted);
Assert.Equal(@"{""unescaped"":""jwt+secevent""}", actualStr);
// actualStr == "{"unescaped":"jwt\u002bsecevent"}"
}
In this test, the '+' character is escaped to '\u002b'.
The expected behavior is to have an unescaped string when it is a JSON value and a value of a JSON property.
petrsvihlik
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonjson-functionality-docMissing JSON specific functionality that needs documentingMissing JSON specific functionality that needs documenting