From 2491737e52fc0f3f3c36c0faa2a6b670c5c4ab54 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 9 Jan 2016 13:14:58 +1300 Subject: [PATCH] -Tests --- .../JsonTextReaderTest.cs | 21 +++++++++++++++++++ Src/Newtonsoft.Json/JsonTextReader.cs | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 47ee206f..d043d7e0 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -1063,6 +1063,27 @@ third line", jsonTextReader.Value); Assert.AreEqual(JsonToken.Null, reader.TokenType); } + [Test] + public void UnexpectedEndAfterReadingN() + { + JsonTextReader reader = new JsonTextReader(new StringReader("n")); + ExceptionAssert.Throws(() => reader.Read(), "Unexpected end when reading JSON. Path '', line 1, position 1."); + } + + [Test] + public void UnexpectedEndAfterReadingNu() + { + JsonTextReader reader = new JsonTextReader(new StringReader("nu")); + ExceptionAssert.Throws(() => reader.Read(), "Unexpected end when reading JSON. Path '', line 1, position 2."); + } + + [Test] + public void UnexpectedEndAfterReadingNe() + { + JsonTextReader reader = new JsonTextReader(new StringReader("ne")); + ExceptionAssert.Throws(() => reader.Read(), "Unexpected end when reading JSON. Path '', line 1, position 2."); + } + [Test] public void ReadInt32Overflow() { diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index 693da178..96a3ee83 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -1564,7 +1564,8 @@ namespace Newtonsoft.Json } else { - CreateUnexpectedEndException(); + _charPos++; + throw CreateUnexpectedEndException(); } return true; case 'N':