-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix +
in json
#3663
base: master
Are you sure you want to change the base?
fix +
in json
#3663
Changes from all commits
0917647
6a77c33
83b1394
3c15c6f
ebb00e7
9bb0fe7
be4c2ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System.Text.Encodings.Web; | ||
using System.Text.Json; | ||
using System.Text.Unicode; | ||
using static Neo.Json.Utility; | ||
|
||
namespace Neo.Json | ||
|
@@ -19,6 +21,13 @@ namespace Neo.Json | |
/// </summary> | ||
public abstract class JToken | ||
{ | ||
public readonly static JavaScriptEncoder DefaultEncoder; | ||
|
||
static JToken() | ||
{ | ||
DefaultEncoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it change the old behaviour except the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checkout #3663 (comment), but it should be the exactly the same with the addition of the |
||
} | ||
|
||
/// <summary> | ||
/// Represents a <see langword="null"/> token. | ||
/// </summary> | ||
|
@@ -239,6 +248,7 @@ public byte[] ToByteArray(bool indented) | |
using Utf8JsonWriter writer = new(ms, new JsonWriterOptions | ||
{ | ||
Indented = indented, | ||
Encoder = DefaultEncoder, | ||
SkipValidation = true | ||
}); | ||
Write(writer); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,10 +175,13 @@ public void JsonTest_Object() | |
|
||
Assert.AreEqual(@"{""test"":true}", parsed.ToString()); | ||
|
||
json = @" {""\uAAAA"": true}"; | ||
json = @" {""test"":""+""} "; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we keep this test-case with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact I think this will be dropped, no way to do it without unsafe relaxing if we use native json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesnt use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
parsed = JObject.Parse(json); | ||
Assert.AreEqual(@"{""test"":""+""}", parsed.ToString()); | ||
cschuchardt88 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Assert.AreEqual(@"{""\uAAAA"":true}", parsed.ToString()); | ||
json = @" {""测试"": true}"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to allow |
||
parsed = JObject.Parse(json); | ||
Assert.AreEqual(@"{""测试"":true}", parsed.ToString()); | ||
|
||
json = @"{""a"":}"; | ||
Assert.ThrowsException<FormatException>(() => JObject.Parse(json)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind allowing the
+
(plus) sign is a security risk, reference: dotnet/runtime#35281Only for XSS injection though.
Note: After searching for hours with no luck for solution. I came up with this solution on my own. Its dirty and could have bugs or exploits, however am 99% sure we don't. Need more tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it works with newtonsoft (according your reference)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newtonsoft uses it own custom library. It doesn't use dotnet built-in JSON libraries.