diff --git a/Src/Newtonsoft.Json.Tests/Converters/StringEnumConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/StringEnumConverterTests.cs index 20a77e78..e7b1be74 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/StringEnumConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/StringEnumConverterTests.cs @@ -376,7 +376,7 @@ namespace Newtonsoft.Json.Tests.Converters try { var serializer = new JsonSerializer(); - serializer.Converters.Add(new StringEnumConverter { DisallowIntegerValues = true }); + serializer.Converters.Add(new StringEnumConverter { AllowIntegerValues = false }); serializer.Deserialize(new JsonTextReader(new StringReader(json))); } catch (JsonSerializationException ex) diff --git a/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathParseTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathParseTests.cs index dd114992..59845a38 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathParseTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JsonPath/JPathParseTests.cs @@ -544,14 +544,23 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath } [Test] - [Ignore] public void MultipleQuotedIndexes() { JPath path = new JPath("['111119990','3']"); Assert.AreEqual(1, path.Filters.Count); - Assert.AreEqual(2, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes.Count); - Assert.AreEqual(111119990, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[0]); - Assert.AreEqual(3, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[1]); + Assert.AreEqual(2, ((FieldMultipleFilter)path.Filters[0]).Names.Count); + Assert.AreEqual("111119990", ((FieldMultipleFilter)path.Filters[0]).Names[0]); + Assert.AreEqual("3", ((FieldMultipleFilter)path.Filters[0]).Names[1]); + } + + [Test] + public void MultipleQuotedIndexesWithWhitespace() + { + JPath path = new JPath("[ '111119990' , '3' ]"); + Assert.AreEqual(1, path.Filters.Count); + Assert.AreEqual(2, ((FieldMultipleFilter)path.Filters[0]).Names.Count); + Assert.AreEqual("111119990", ((FieldMultipleFilter)path.Filters[0]).Names[0]); + Assert.AreEqual("3", ((FieldMultipleFilter)path.Filters[0]).Names[1]); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 8ca28e0d..4922c0cb 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -75,4 +75,4 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.8.16808")] +[assembly: AssemblyFileVersion("5.0.8.16815")] diff --git a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs index a12c54b8..c1de6ac5 100644 --- a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs +++ b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs @@ -52,10 +52,18 @@ namespace Newtonsoft.Json.Converters public bool CamelCaseText { get; set; } /// - /// Gets or sets a value indicating whether integer values are disallowed. + /// Gets or sets a value indicating whether integer values are allowed. /// - /// true if integers are disallowed; otherwise, false. - public bool DisallowIntegerValues { get; set; } + /// true if integers are allowed; otherwise, false. + public bool AllowIntegerValues { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public StringEnumConverter() + { + AllowIntegerValues = true; + } /// /// Writes the JSON representation of the object. @@ -159,7 +167,7 @@ namespace Newtonsoft.Json.Converters if (reader.TokenType == JsonToken.Integer) { - if (DisallowIntegerValues) + if (!AllowIntegerValues) throw JsonSerializationException.Create(reader, "Integer value {0} is not allowed.".FormatWith(CultureInfo.InvariantCulture, reader.Value)); return ConvertUtils.ConvertOrCast(reader.Value, CultureInfo.InvariantCulture, t); diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs new file mode 100644 index 00000000..1fbabcbe --- /dev/null +++ b/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Globalization; +using Newtonsoft.Json.Utilities; + +namespace Newtonsoft.Json.Linq.JsonPath +{ + internal class FieldMultipleFilter : PathFilter + { + public List Names { get; set; } + + public override IEnumerable ExecuteFilter(IEnumerable current, bool errorWhenNoMatch) + { + foreach (JToken t in current) + { + JObject o = t as JObject; + if (o != null) + { + foreach (string name in Names) + { + JToken v = o[name]; + + if (v != null) + yield return v; + } + } + //else + //{ + // if (errorWhenNoMatch) + // throw new JsonException("Property '{0}' not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, Name ?? "*", t.GetType().Name)); + //} + } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs b/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs index 92634d0e..7c4d6093 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs @@ -472,36 +472,7 @@ namespace Newtonsoft.Json.Linq.JsonPath char currentChar = _expression[_currentIndex]; if (currentChar == '\'') { - StringBuilder sb = new StringBuilder(); - - _currentIndex++; - while (_currentIndex < _expression.Length) - { - currentChar = _expression[_currentIndex]; - if (currentChar == '\\' && _currentIndex + 1 < _expression.Length) - { - _currentIndex++; - - if (_expression[_currentIndex] == '\'') - sb.Append('\''); - else if (_expression[_currentIndex] == '\\') - sb.Append('\\'); - else - throw new JsonException(@"Unknown escape chracter: \" + _expression[_currentIndex]); - - _currentIndex++; - } - else if (currentChar == '\'') - { - _currentIndex++; - return sb.ToString(); - } - else - { - _currentIndex++; - sb.Append(currentChar); - } - } + return ReadQuotedString(); } else if (char.IsDigit(currentChar) || currentChar == '-') { @@ -559,6 +530,44 @@ namespace Newtonsoft.Json.Linq.JsonPath throw new JsonException("Could not read query value."); } + private string ReadQuotedString() + { + StringBuilder sb = new StringBuilder(); + + _currentIndex++; + while (_currentIndex < _expression.Length) + { + char currentChar = _expression[_currentIndex]; + if (currentChar == '\\' && _currentIndex + 1 < _expression.Length) + { + _currentIndex++; + + if (_expression[_currentIndex] == '\'') + sb.Append('\''); + else if (_expression[_currentIndex] == '\\') + sb.Append('\\'); + else + throw new JsonException(@"Unknown escape chracter: \" + _expression[_currentIndex]); + + _currentIndex++; + } + else if (currentChar == '\'') + { + _currentIndex++; + { + return sb.ToString(); + } + } + else + { + _currentIndex++; + sb.Append(currentChar); + } + } + + throw new JsonException("Path ended with an open string."); + } + private bool Match(string s) { int currentPosition = _currentIndex; @@ -595,34 +604,50 @@ namespace Newtonsoft.Json.Linq.JsonPath throw new JsonException("Could not read query operator."); } - private FieldFilter ParseQuotedField(char indexerCloseChar) + private PathFilter ParseQuotedField(char indexerCloseChar) { - _currentIndex++; - int start = _currentIndex; + //_currentIndex++; + //int start = _currentIndex; + + List fields = null; while (_currentIndex < _expression.Length) { - char currentCharacter = _expression[_currentIndex]; - if (currentCharacter == '\'') + string field = ReadQuotedString(); + + //_currentIndex++; + //EnsureLength("Path ended with open indexer."); + EatWhitespace(); + EnsureLength("Path ended with open indexer."); + + if (_expression[_currentIndex] == indexerCloseChar) + { + _currentIndex++; + + if (fields != null) + { + fields.Add(field); + return new FieldMultipleFilter { Names = fields }; + } + else + { + return new FieldFilter { Name = field }; + } + } + else if (_expression[_currentIndex] == ',') { - int length = _currentIndex - start; - - if (length == 0) - throw new JsonException("Empty path indexer."); - - // check that character after the quote is to close the index _currentIndex++; - EnsureLength("Path ended with open indexer."); EatWhitespace(); - if (_expression[_currentIndex] != indexerCloseChar) - throw new JsonException("Unexpected character while parsing path indexer: " + currentCharacter); + if (fields == null) + fields = new List(); - string indexer = _expression.Substring(start, length); - return new FieldFilter { Name = indexer }; + fields.Add(field); + } + else + { + throw new JsonException("Unexpected character while parsing path indexer: " + _expression[_currentIndex]); } - - _currentIndex++; } throw new JsonException("Path ended with open indexer."); diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj index 9cba95ac..1df70fc0 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj @@ -111,6 +111,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj index a9806a4c..0e449f82 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj @@ -123,6 +123,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj index 7c798394..ed91782f 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj @@ -124,6 +124,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj index a069c0d1..e78b4349 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj @@ -115,6 +115,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj index 5d36b70e..d7f53d12 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj @@ -121,6 +121,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj index 85c78d1b..b8d4b249 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj @@ -187,6 +187,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index 116396dd..5b9ae869 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -116,6 +116,7 @@ + diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index bf252a6e..8e31cb5f 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -91,5 +91,5 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.8.16808")] +[assembly: AssemblyFileVersion("5.0.8.16815")] [assembly: CLSCompliant(true)]