2
0
Эх сурвалжийг харах

Fix JSON parser line number initialization for empty string (#827)

Marko Lahma 4 жил өмнө
parent
commit
6880a994ff

+ 7 - 0
Jint.Tests/Runtime/EngineTests.cs

@@ -1216,6 +1216,13 @@ myarr[0](0);
             ");
         }
 
+        [Fact]
+        public void JsonParserShouldHandleEmptyString()
+        {
+            var ex = Assert.Throws<ParserException>(() => _engine.Execute("JSON.parse('');"));
+            Assert.Equal("Line 1: Unexpected end of input", ex.Message);
+       }
+
         [Fact]
         [ReplaceCulture("fr-FR")]
         public void ShouldBeCultureInvariant()

+ 1 - 1
Jint/Native/Json/JsonParser.cs

@@ -797,7 +797,7 @@ namespace Jint.Native.Json
         {
             _source = code;
             _index = 0;
-            _lineNumber = (_source.Length > 0) ? 1 : 0;
+            _lineNumber = 1;
             _lineStart = 0;
             _length = _source.Length;
             _lookahead = null;