-Fixed escaping special characters in generated JSONPaths

-Fixed reading escaped special characters in JSONPaths
This commit is contained in:
James Newton-King
2018-01-27 18:39:44 +13:00
parent 0b975a2087
commit 6360cc4c4b
4 changed files with 142 additions and 18 deletions
@@ -34,6 +34,7 @@ using Newtonsoft.Json.Converters;
using Xunit;
using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
using TestCase = Xunit.InlineDataAttribute;
#else
using NUnit.Framework;
#endif
@@ -1290,5 +1291,37 @@ namespace Newtonsoft.Json.Tests.Linq
ExceptionAssert.Throws<JsonReaderException>(() => JToken.Parse(json),
"Additional text encountered after finished reading JSON content: {. Path '', line 3, position 0.");
}
#if DNXCORE50
[Theory]
#endif
[TestCase("test customer", "['test customer']")]
[TestCase("test customer's", "['test customer\\'s']")]
[TestCase("testcustomer's", "['testcustomer\\'s']")]
[TestCase("testcustomer", "testcustomer")]
[TestCase("test.customer", "['test.customer']")]
[TestCase("test\rcustomer", "['test\\rcustomer']")]
[TestCase("test\ncustomer", "['test\\ncustomer']")]
[TestCase("test\tcustomer", "['test\\tcustomer']")]
[TestCase("test\bcustomer", "['test\\bcustomer']")]
[TestCase("test\fcustomer", "['test\\fcustomer']")]
[TestCase("test/customer", "['test/customer']")]
[TestCase("test\\customer", "['test\\\\customer']")]
[TestCase("\"test\"customer", "['\"test\"customer']")]
public void PathEscapingTest(string name, string expectedPath)
{
JValue v = new JValue("12345");
JObject o = new JObject
{
[name] = v
};
string path = v.Path;
Assert.AreEqual(expectedPath, path);
JToken token = o.SelectToken(path);
Assert.AreEqual(v, token);
}
}
}