diff --git a/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathExecuteTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathExecuteTests.cs index 81952314..7d914237 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathExecuteTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathExecuteTests.cs @@ -272,6 +272,16 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath () => { o.SelectToken("Missing", true); }); } + [Test] + public void EvaluatePropertyWithoutError() + { + JObject o = new JObject( + new JProperty("Blah", 1)); + + JValue v = (JValue)o.SelectToken("Blah", true); + Assert.AreEqual(1L, v.Value); + } + [Test] public void EvaluateMissingPropertyIndexWithError() { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs index 2b9bfaa0..d3fe1f01 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs @@ -21,8 +21,7 @@ namespace Newtonsoft.Json.Linq.JsonPath if (v != null) yield return v; - - if (errorWhenNoMatch) + else if (errorWhenNoMatch) throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, Name)); } else