From e75ea148f44f742d013c4e299609838ba1ce7cdf Mon Sep 17 00:00:00 2001 From: Michael Mairegger Date: Wed, 11 Nov 2015 13:59:33 +0100 Subject: [PATCH 1/2] Changed XML-Comment --- Src/Newtonsoft.Json/MemberSerialization.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Newtonsoft.Json/MemberSerialization.cs b/Src/Newtonsoft.Json/MemberSerialization.cs index bb68cd502..830999298 100644 --- a/Src/Newtonsoft.Json/MemberSerialization.cs +++ b/Src/Newtonsoft.Json/MemberSerialization.cs @@ -42,7 +42,7 @@ public enum MemberSerialization OptOut = 0, /// - /// Only members must be marked with or are serialized. + /// Only members marked with or are serialized. /// This member serialization mode can also be set by marking the class with . /// OptIn = 1, @@ -55,4 +55,4 @@ public enum MemberSerialization Fields = 2 #pragma warning restore 1584,1711,1572,1581,1580,1574 } -} \ No newline at end of file +} From 5ddbc508f0b9f19243076821c825a7f5056de4b1 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 9 Mar 2016 16:34:02 +1300 Subject: [PATCH 2/2] -Fixed JSON string encoder not getting buffer from buffer pool --- Src/Newtonsoft.Json.Tests/DemoTests.cs | 30 ++++++++++--------- .../JsonTextWriterTest.cs | 28 +++++++++++++++++ .../Newtonsoft.Json.Tests.project.json | 2 +- Src/Newtonsoft.Json.Tests/project.json | 2 +- .../Utilities/JavaScriptUtils.cs | 2 +- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/DemoTests.cs b/Src/Newtonsoft.Json.Tests/DemoTests.cs index d0b6cd574..2214bd8df 100644 --- a/Src/Newtonsoft.Json.Tests/DemoTests.cs +++ b/Src/Newtonsoft.Json.Tests/DemoTests.cs @@ -609,23 +609,25 @@ public void ArrayPooling() Assert.AreEqual(4, value.Count); } +#endif + } - public class JsonArrayPool : IArrayPool - { - public static readonly JsonArrayPool Instance = new JsonArrayPool(); +#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE || PORTABLE40 || DNXCORE50) + public class JsonArrayPool : IArrayPool + { + public static readonly JsonArrayPool Instance = new JsonArrayPool(); - public char[] Rent(int minimumLength) - { - // use System.Buffers shared pool - return ArrayPool.Shared.Rent(minimumLength); - } + public char[] Rent(int minimumLength) + { + // use System.Buffers shared pool + return ArrayPool.Shared.Rent(minimumLength); + } - public void Return(char[] array) - { - // use System.Buffers shared pool - ArrayPool.Shared.Return(array); - } + public void Return(char[] array) + { + // use System.Buffers shared pool + ArrayPool.Shared.Return(array); } -#endif } +#endif } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs index 6caadd732..fe76b3798 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs @@ -49,6 +49,7 @@ using Newtonsoft.Json; using System.IO; using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; using Newtonsoft.Json.Utilities; namespace Newtonsoft.Json.Tests @@ -136,6 +137,33 @@ public void BufferTest_WithError() Assert.AreEqual(1, arrayPool.FreeArrays.Count); } +#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE || PORTABLE40 || DNXCORE50) + [Test] + public void BufferErroringWithInvalidSize() + { + JObject o = new JObject + { + {"BodyHtml", "

Title!

" + Environment.NewLine + new string(' ', 100) + "

Content!

"} + }; + + JsonArrayPool arrayPool = new JsonArrayPool(); + + StringWriter sw = new StringWriter(); + using (JsonTextWriter writer = new JsonTextWriter(sw)) + { + writer.ArrayPool = arrayPool; + + o.WriteTo(writer); + } + + string result = o.ToString(); + + Assert.AreEqual(@"{ + ""BodyHtml"": ""

Title!

\r\n

Content!

"" +}", result); + } +#endif + [Test] public void NewLine() { diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json index b13cce539..51db2f8c2 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json @@ -3,7 +3,7 @@ "Autofac": "4.0.0-beta7-130", "FSharp.Core": "4.0.0.1", "NUnit": "2.6.2", - "System.Buffers": "4.0.0-rc2-23623", + "System.Buffers": "4.0.0-rc2-23826", "System.Collections.Immutable": "1.1.37" }, "frameworks": { diff --git a/Src/Newtonsoft.Json.Tests/project.json b/Src/Newtonsoft.Json.Tests/project.json index 6bb0ab8a6..5c105e652 100644 --- a/Src/Newtonsoft.Json.Tests/project.json +++ b/Src/Newtonsoft.Json.Tests/project.json @@ -33,7 +33,7 @@ "FSharp.Core": "4.0.0.1", "NUnit": "2.6.4", "System.Collections.Immutable": "1.1.37", - "System.Buffers": "4.0.0-rc2-23623" + "System.Buffers": "4.0.0-rc2-23826" } }, "net40": { diff --git a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs index 4fe8b0519..e8ef53e7d 100644 --- a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs @@ -286,7 +286,7 @@ public static void WriteEscapedJavaScriptString(TextWriter writer, string s, cha if (writeBuffer == null || writeBuffer.Length < length) { - writeBuffer = new char[length]; + writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, length, writeBuffer); } s.CopyTo(lastWritePosition, writeBuffer, 0, length);