-
Notifications
You must be signed in to change notification settings - Fork 5.1k
feat(83547): Adding escaping of property name for GetPath. #84688
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
Changes from all commits
dc50db0
a6fb353
1759a92
67fb358
51fcbb0
a610e38
4a0d7b1
6cb8d88
e093c8e
002503c
6ac4eba
1c5baab
f114e44
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace System.Text.Json.Nodes.Tests | ||
|
@@ -76,6 +77,17 @@ public static void GetPathAndRoot() | |
Assert.Equal("$[0].Child", node[0]["Child"].GetPath()); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetPath_ShouldReturnExpectedValue_TestData))] | ||
public static void GetPath_ShouldReturnExpectedValue(JsonNode jsonNode, string expectedValue) | ||
{ | ||
string actualValue; | ||
|
||
actualValue = jsonNode.GetPath(); | ||
|
||
Assert.Equal(expectedValue, actualValue); | ||
} | ||
|
||
[Fact] | ||
public static void GetPath_SpecialCharacters() | ||
{ | ||
|
@@ -180,5 +192,49 @@ public static void Parent_Object() | |
parent.Add("MyProp", child); | ||
Assert.True(child.Options.Value.PropertyNameCaseInsensitive); | ||
} | ||
|
||
public static IEnumerable<object[]> GetPath_ShouldReturnExpectedValue_TestData() | ||
{ | ||
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 commentThe 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. 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. @Maximys would it be possible to revisit this? Thanks! |
||
}; | ||
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot":{"foo[\"bar":"baz"}}""")["$myRoot"]["foo[\"bar"], | ||
"$.$myRoot['foo[\\u0022bar']" | ||
}; | ||
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot":{"foo['b\"ar":"baz"}}""")["$myRoot"]["foo['b\"ar"], | ||
"$.$myRoot['foo[\\u0027b\\u0022ar']" | ||
}; | ||
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot": {"myRoot'child": {"myRoot'child'secondLevelChild": "value1"}}}""")["$myRoot"]["myRoot'child"]["myRoot'child'secondLevelChild"], | ||
"$.$myRoot['myRoot\\u0027child']['myRoot\\u0027child\\u0027secondLevelChild']" | ||
}; | ||
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot": {"myRoot\"child": {"myRoot\"child\"secondLevelChild": "value1"}}}""")["$myRoot"]["myRoot\"child"]["myRoot\"child\"secondLevelChild"], | ||
"$.$myRoot['myRoot\\u0022child']['myRoot\\u0022child\\u0022secondLevelChild']" | ||
}; | ||
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot": {"myRoot\"child": {"myRoot'child\"secondLevelChild": "value1"}}}""")["$myRoot"]["myRoot\"child"]["myRoot'child\"secondLevelChild"], | ||
"$.$myRoot['myRoot\\u0022child']['myRoot\\u0027child\\u0022secondLevelChild']" | ||
}; | ||
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot": {"myRoot'child": {"secondLevelChildWithoutEscaping": "value2"}}}""")["$myRoot"]["myRoot'child"]["secondLevelChildWithoutEscaping"], | ||
"$.$myRoot['myRoot\\u0027child'].secondLevelChildWithoutEscaping" | ||
}; | ||
yield return new object[] | ||
{ | ||
JsonNode.Parse("""{"$myRoot": {"myRoot\"child": {"secondLevelChildWithoutEscaping": "value2"}}}""")["$myRoot"]["myRoot\"child"]["secondLevelChildWithoutEscaping"], | ||
"$.$myRoot['myRoot\\u0022child'].secondLevelChildWithoutEscaping" | ||
}; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.