-
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
Conversation
This can lead to some state diff, needs to be checked. |
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.
This is how you do it Check out https://www.unicode.org/charts/PDF/U0000.pdf for Basic Latin Unicode block (U+0021-U+007F).
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.
@shargon
I fixed the issue on the branch for you. Check and test changes.
@@ -76,7 +76,7 @@ public override T GetEnum<T>(bool ignoreCase = false) | |||
|
|||
internal override void Write(Utf8JsonWriter writer) | |||
{ | |||
writer.WriteStringValue(Value); | |||
writer.WriteRawValue($"\"{DefaultEncoder.Encode(Value).Replace("\\u002B", "+")}\""); |
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#35281
Only 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.
|
||
Assert.AreEqual(@"{""\uAAAA"":true}", parsed.ToString()); | ||
json = @" {""测试"": true}"; |
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.
Had to allow UnicodeRanges.CjkUnifiedIdeographs
for these characters for json DefaultEncoder
.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep this test-case with \uAAAA
? It's a nice compatibility test for NeoGo.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Doesnt use unsafe relaxing
currently. And its working fine now.
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.
Replace
is a dirty fix, performance is affected always, not only when it contains +
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.
|
||
static JToken() | ||
{ | ||
DefaultEncoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs); |
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.
Does it change the old behaviour except the +
symbol?
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.
Checkout #3663 (comment), but it should be the exactly the same with the addition of the +
(plus sign).
Description
Fix #2612
Based on https://github.com/neo-project/neo/pull/2050/files
Type of change
How Has This Been Tested?
JsonTest_Object
Test Configuration:
Checklist: