-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(83547): Adding escaping of property name for GetPath. #84688
feat(83547): Adding escaping of property name for GetPath. #84688
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsCurrent PR fix problem with unescaped single quote, but it does not fix problem with shorthand property.
output: "$myRoot['myRoot'child'].secondLevelChildWithoutEscaping" I think, Newtonsoft is is etalon implementation of JSON library, but nobody of us protected from mistake.
|
9660f1c
to
b4b8b21
Compare
string returnValue; | ||
|
||
returnValue = rawPropertyName | ||
.Replace(SingleQuote, EscapedSingleQuote); |
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.
I wanted to use here Regex.Replace(String, String, String, RegexOptions), but I could not understand how to use System.Text.RegularExpressions assembly from current.
@layomia , could you review current PR? |
@Maximys looks there are some related test failures because of this change. Could you please have a look? |
If the shorthand problem isn't being addressed, the issue should remain open. This PR isn't a complete fix. |
@tarekgh , ok, I'll try to look |
2d3bd99
to
5cd4b25
Compare
tarekgh , failed tests was linked with invalid processing of quote('"') symbol by JsonSourceGenerator. I had removed this symbol from JsonPropertyName of ClassWithEscapablePropertyName and all tests was passed. |
@layomia @eiriktsarpalis could you please have a look at this change. The change is reasonable to me, but I want to ensure this is not breaking in anyway. Thanks! |
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs
Outdated
Show resolved
Hide resolved
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.
Escaping should consistent with what JsonSerializerOptions.Encoder
is doing.
ea4813e
to
75deded
Compare
@eiriktsarpalis , could I ask little question, which is not linked with current PR? I want try to fix #86031 by separate PR. I want to use FluentAssertions for check result of my fix. As I can see, Rutime currently use this library only for test installer. May I add FluentAssertions to TestUtilities inside Common? |
|
{ | ||
string returnValue; | ||
|
||
if (value is null) | ||
{ | ||
returnValue = "null"; | ||
} | ||
else | ||
{ | ||
returnValue = SyntaxFactory.Literal(value).ToFullString(); | ||
} | ||
|
||
return returnValue; | ||
} |
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.
Seems like this can be simplified
{ | |
string returnValue; | |
if (value is null) | |
{ | |
returnValue = "null"; | |
} | |
else | |
{ | |
returnValue = SyntaxFactory.Literal(value).ToFullString(); | |
} | |
return returnValue; | |
} | |
=> value is null ? "null" : SyntaxFactory.Literal(value).ToFullString(); |
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.
Fixed by 51fcbb0
@@ -1000,7 +1000,6 @@ private bool IsValidDataExtensionPropertyType(ITypeSymbol type) | |||
{ | |||
ImmutableArray<TypedConstant> ctorArgs = attributeData.ConstructorArguments; | |||
jsonPropertyName = (string)ctorArgs[0].Value!; | |||
// Null check here is done at runtime within JsonSerializer. |
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.
Is this change related?
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.
No, fixed by amend
…pertyName(string, JavaScriptEncoder?)" implementation." This reverts commit d346c16f342c282a456c18d7f4f95e88f43a6cad.
75deded
to
4a0d7b1
Compare
@Maximys of this isn't going to be addressed, can you remove the "fixes" text from the opening comment, please? Alternatively, a secondary issue should be opened to cover the shorthand problem. |
src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs
Outdated
Show resolved
Hide resolved
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.
Thanks!
@gregsdennis Presumably you mean the bracketing of properties starting with the dollar sign? Or is it missing something else? |
Yes, that. What's being generated isn't a valid path. If that's not fixed, the issue isn't resolved. |
@Maximys I don't think we need to base our behavior on what Json.NET is doing. |
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot":{"foo['bar":"baz"}}""")["$myRoot"]["foo['bar"], | ||
"$.$myRoot['foo[\\u0027bar']" |
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.
If I'm reading these tests right, they're still not creating the correct paths. $myRoot
isn't valid for the dot syntax and needs to be bracketed.
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.
@Maximys would it be possible to revisit this? Thanks!
This pull request has been automatically marked |
This pull request will now be closed since it had been marked |
Current PR fix problem with unescaped single quote, but it does not fix problem with shorthand property.
I did so because Newtonsoft.Json 13.0.3 have the same behavior:
output: "$myRoot['myRoot'child'].secondLevelChildWithoutEscaping"
I think, Newtonsoft is is etalon implementation of JSON library, but nobody of us protected from mistake.
Add some comment if this behaviour invalid.
Contributes to #83547