Skip to content

Commit 16c864f

Browse files
committed
Update upstream files
1 parent 1da63c6 commit 16c864f

26 files changed

+2923
-9
lines changed

src/Newtonsoft.Json/Linq/JsonPath/ArrayIndexFilter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
1414
{
1515
if (Index != null)
1616
{
17-
JToken v = GetTokenIndex(t, errorWhenNoMatch, Index.Value);
17+
JToken v = GetTokenIndex(t, errorWhenNoMatch, Index.GetValueOrDefault());
1818

1919
if (v != null)
20+
{
2021
yield return v;
22+
}
2123
}
2224
else
2325
{
@@ -31,7 +33,9 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
3133
else
3234
{
3335
if (errorWhenNoMatch)
36+
{
3437
throw new JsonException("Index * not valid on {0}.".FormatWith(CultureInfo.InvariantCulture, t.GetType().Name));
38+
}
3539
}
3640
}
3741
}

src/Newtonsoft.Json/Linq/JsonPath/ArrayMultipleIndexFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
1515
JToken v = GetTokenIndex(t, errorWhenNoMatch, i);
1616

1717
if (v != null)
18+
{
1819
yield return v;
20+
}
1921
}
2022
}
2123
}

src/Newtonsoft.Json/Linq/JsonPath/ArraySliceFilter.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ internal class ArraySliceFilter : PathFilter
1414
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
1515
{
1616
if (Step == 0)
17+
{
1718
throw new JsonException("Step cannot be zero.");
19+
}
1820

1921
foreach (JToken t in current)
2022
{
@@ -27,10 +29,16 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
2729
int stopIndex = End ?? ((stepCount > 0) ? a.Count : -1);
2830

2931
// start from the end of the list if start is negitive
30-
if (Start < 0) startIndex = a.Count + startIndex;
32+
if (Start < 0)
33+
{
34+
startIndex = a.Count + startIndex;
35+
}
3136

3237
// end from the start of the list if stop is negitive
33-
if (End < 0) stopIndex = a.Count + stopIndex;
38+
if (End < 0)
39+
{
40+
stopIndex = a.Count + stopIndex;
41+
}
3442

3543
// ensure indexes keep within collection bounds
3644
startIndex = Math.Max(startIndex, (stepCount > 0) ? 0 : int.MinValue);
@@ -50,23 +58,29 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
5058
else
5159
{
5260
if (errorWhenNoMatch)
61+
{
5362
throw new JsonException("Array slice of {0} to {1} returned no results.".FormatWith(CultureInfo.InvariantCulture,
54-
Start != null ? Start.Value.ToString(CultureInfo.InvariantCulture) : "*",
55-
End != null ? End.Value.ToString(CultureInfo.InvariantCulture) : "*"));
63+
Start != null ? Start.GetValueOrDefault().ToString(CultureInfo.InvariantCulture) : "*",
64+
End != null ? End.GetValueOrDefault().ToString(CultureInfo.InvariantCulture) : "*"));
65+
}
5666
}
5767
}
5868
else
5969
{
6070
if (errorWhenNoMatch)
71+
{
6172
throw new JsonException("Array slice is not valid on {0}.".FormatWith(CultureInfo.InvariantCulture, t.GetType().Name));
73+
}
6274
}
6375
}
6476
}
6577

6678
private bool IsValid(int index, int stopIndex, bool positiveStep)
6779
{
6880
if (positiveStep)
81+
{
6982
return (index < stopIndex);
83+
}
7084

7185
return (index > stopIndex);
7286
}

src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
2020
JToken v = o[Name];
2121

2222
if (v != null)
23+
{
2324
yield return v;
25+
}
2426
else if (errorWhenNoMatch)
27+
{
2528
throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, Name));
29+
}
2630
}
2731
else
2832
{
@@ -35,7 +39,9 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
3539
else
3640
{
3741
if (errorWhenNoMatch)
42+
{
3843
throw new JsonException("Property '{0}' not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, Name ?? "*", t.GetType().Name));
44+
}
3945
}
4046
}
4147
}

src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, b
2525
JToken v = o[name];
2626

2727
if (v != null)
28+
{
2829
yield return v;
30+
}
2931

3032
if (errorWhenNoMatch)
33+
{
3134
throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, name));
35+
}
3236
}
3337
}
3438
else
3539
{
3640
if (errorWhenNoMatch)
41+
{
3742
throw new JsonException("Properties {0} not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, string.Join(", ", Names.Select(n => "'" + n + "'").ToArray()), t.GetType().Name));
43+
}
3844
}
3945
}
4046
}

0 commit comments

Comments
 (0)