Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/Newtonsoft.Json.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs19
-rw-r--r--Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs13
-rw-r--r--Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs18
-rw-r--r--Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs13
-rw-r--r--Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj3
-rw-r--r--Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs2
-rw-r--r--Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs2
-rw-r--r--Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs24
-rw-r--r--Src/Newtonsoft.Json/Converters/StringEnumConverter.cs2
-rw-r--r--Src/Newtonsoft.Json/Linq/JArray.cs7
-rw-r--r--Src/Newtonsoft.Json/Linq/JObject.cs7
-rw-r--r--Src/Newtonsoft.Json/Linq/JToken.cs7
-rw-r--r--Src/Newtonsoft.Json/Properties/AssemblyInfo.cs2
13 files changed, 100 insertions, 19 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs
index a4935ae..00ed770 100644
--- a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs
@@ -1243,5 +1243,24 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.AreEqual(new byte[] { 72, 63, 62, 71, 92, 55 }, newObject.Data);
}
}
+
+#if !(WINDOWS_PHONE || SILVERLIGHT || NET20 || NET35)
+ public void Utf8Text()
+ {
+ string badText =System.IO.File.ReadAllText(@"PoisonText.txt");
+ var j = new JObject();
+ j["test"] = badText;
+
+ var memoryStream = new MemoryStream();
+ var bsonWriter = new BsonWriter(memoryStream);
+ j.WriteTo(bsonWriter);
+ bsonWriter.Flush();
+
+ memoryStream.Position = 0;
+ JObject o = JObject.Load(new BsonReader(memoryStream));
+
+ Assert.AreEqual(badText, (string)o["test"]);
+ }
+#endif
}
} \ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs
index ff612b5..030a8fd 100644
--- a/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs
@@ -448,5 +448,18 @@ Parameter name: index")]
Assert.AreEqual(123, (int)array[0]);
Assert.AreEqual(456, (int)array[1]);
}
+
+ [Test]
+ [ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected state: Finished. Line 5, position 3.")]
+ public void ParseAdditionalContent()
+ {
+ string json = @"[
+""Small"",
+""Medium"",
+""Large""
+], 987987";
+
+ JArray.Parse(json);
+ }
}
} \ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs
index 587ffdb..959daec 100644
--- a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs
@@ -1624,5 +1624,23 @@ Parameter name: arrayIndex")]
Assert.AreEqual("9065acf3-c820-467d-be50-8d4664beaf35", v.ToString());
}
+
+ [Test]
+ [ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected state: Finished. Line 10, position 3.")]
+ public void ParseAdditionalContent()
+ {
+ string json = @"{
+""Name"": ""Apple"",
+""Expiry"": new Date(1230422400000),
+""Price"": 3.99,
+""Sizes"": [
+""Small"",
+""Medium"",
+""Large""
+]
+}, 987987";
+
+ JObject o = JObject.Parse(json);
+ }
}
} \ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
index 5b2e05b..a5ceea0 100644
--- a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
@@ -739,5 +739,18 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.IsTrue(v1.DeepEquals(v2));
}
+
+ [Test]
+ [ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected state: Finished. Line 5, position 3.")]
+ public void ParseAdditionalContent()
+ {
+ string json = @"[
+""Small"",
+""Medium"",
+""Large""
+], 987987";
+
+ JToken.Parse(json);
+ }
}
} \ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
index 8b90838..bbd3840 100644
--- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
+++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
@@ -306,6 +306,9 @@
<Content Include="bunny_pancake.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <Content Include="PoisonText.txt">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
index 13aae91..e24a613 100644
--- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
+++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
@@ -66,5 +66,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.3.0")]
#if !PocketPC
-[assembly: AssemblyFileVersion("4.0.3.14302")]
+[assembly: AssemblyFileVersion("4.0.3.14319")]
#endif
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
index fd1930e..fd394f2 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
@@ -5046,6 +5046,7 @@ keyword such as type of business.""
}
}
+#if !(SILVERLIGHT || WINDOWS_PHONE || NET20)
[Test]
public void DeserializeDecimalsWithCulture()
{
@@ -5071,6 +5072,7 @@ keyword such as type of business.""
Thread.CurrentThread.CurrentUICulture = initialCulture;
}
}
+#endif
}
public class DecimalTestClass
diff --git a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs
index c9ee4bd..fdd0abe 100644
--- a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs
+++ b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs
@@ -10,7 +10,7 @@ namespace Newtonsoft.Json.Bson
{
internal class BsonBinaryWriter
{
- private static readonly Encoding Encoding = Encoding.UTF8;
+ private static readonly Encoding Encoding = new UTF8Encoding(false);
private readonly BinaryWriter _writer;
@@ -169,12 +169,19 @@ namespace Newtonsoft.Json.Bson
if (calculatedlengthPrefix != null)
_writer.Write(calculatedlengthPrefix.Value);
+ WriteUtf8Bytes(s, byteCount);
+
+ _writer.Write((byte)0);
+ }
+
+ public void WriteUtf8Bytes(string s, int byteCount)
+ {
if (s != null)
{
if (_largeByteBuffer == null)
{
_largeByteBuffer = new byte[256];
- _maxChars = 256/Encoding.GetMaxByteCount(1);
+ _maxChars = 256 / Encoding.GetMaxByteCount(1);
}
if (byteCount <= 256)
{
@@ -183,19 +190,10 @@ namespace Newtonsoft.Json.Bson
}
else
{
- int charCount;
- int totalCharsWritten = 0;
- for (int i = s.Length; i > 0; i -= charCount)
- {
- charCount = (i > _maxChars) ? _maxChars : i;
- int count = Encoding.GetBytes(s, totalCharsWritten, charCount, _largeByteBuffer, 0);
- _writer.Write(_largeByteBuffer, 0, count);
- totalCharsWritten += charCount;
- }
+ byte[] bytes = Encoding.GetBytes(s);
+ _writer.Write(bytes);
}
}
-
- _writer.Write((byte)0);
}
private int CalculateSize(int stringByteCount)
diff --git a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs
index e463ca2..cc5d480 100644
--- a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs
@@ -81,7 +81,7 @@ namespace Newtonsoft.Json.Converters
if (CamelCaseText)
{
- var names = resolvedEnumName.Split(',').Select(item => StringUtils.ToCamelCase(item.Trim()));
+ string[] names = resolvedEnumName.Split(',').Select(item => StringUtils.ToCamelCase(item.Trim())).ToArray();
resolvedEnumName = string.Join(", ", names);
}
diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs
index 1c5ff74..19058b9 100644
--- a/Src/Newtonsoft.Json/Linq/JArray.cs
+++ b/Src/Newtonsoft.Json/Linq/JArray.cs
@@ -136,7 +136,12 @@ namespace Newtonsoft.Json.Linq
{
JsonReader jsonReader = new JsonTextReader(new StringReader(json));
- return Load(jsonReader);
+ JArray a = Load(jsonReader);
+
+ if (jsonReader.Read() && jsonReader.TokenType != JsonToken.Comment)
+ throw new Exception("Additional text found in JSON string after parsing content.");
+
+ return a;
}
/// <summary>
diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs
index 3091c0f..a12aa22 100644
--- a/Src/Newtonsoft.Json/Linq/JObject.cs
+++ b/Src/Newtonsoft.Json/Linq/JObject.cs
@@ -342,7 +342,12 @@ namespace Newtonsoft.Json.Linq
{
JsonReader jsonReader = new JsonTextReader(new StringReader(json));
- return Load(jsonReader);
+ JObject o = Load(jsonReader);
+
+ if (jsonReader.Read() && jsonReader.TokenType != JsonToken.Comment)
+ throw new Exception("Additional text found in JSON string after parsing content.");
+
+ return o;
}
/// <summary>
diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs
index 7bc84f3..4b10983 100644
--- a/Src/Newtonsoft.Json/Linq/JToken.cs
+++ b/Src/Newtonsoft.Json/Linq/JToken.cs
@@ -1229,7 +1229,12 @@ namespace Newtonsoft.Json.Linq
{
JsonReader jsonReader = new JsonTextReader(new StringReader(json));
- return Load(jsonReader);
+ JToken t = Load(jsonReader);
+
+ if (jsonReader.Read() && jsonReader.TokenType != JsonToken.Comment)
+ throw new Exception("Additional text found in JSON string after parsing content.");
+
+ return t;
}
/// <summary>
diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs
index 97643c9..28b5ac3 100644
--- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs
+++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs
@@ -85,7 +85,7 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.3.0")]
#if !PocketPC
-[assembly: AssemblyFileVersion("4.0.3.14302")]
+[assembly: AssemblyFileVersion("4.0.3.14319")]
#endif
[assembly: CLSCompliant(true)]