Ver código fonte

Fix unescape at end of string (#831)

Marko Lahma 4 anos atrás
pai
commit
556792009f

+ 15 - 0
Jint.Tests.Test262/BuiltIns/AnnexB/EscapeTests.cs

@@ -0,0 +1,15 @@
+using Xunit;
+
+namespace Jint.Tests.Test262.BuiltIns.AnnexB
+{
+    public class EscapeTests : Test262Test
+    {
+        [Theory(DisplayName = "annexB\\built-ins\\escape")]
+        [MemberData(nameof(SourceFiles), "annexB\\built-ins\\escape", false)]
+        [MemberData(nameof(SourceFiles), "annexB\\built-ins\\escape", true, Skip = "Skipped")]
+        protected void RunTest(SourceFile sourceFile)
+        {
+            RunTestInternal(sourceFile);
+        }
+    }
+}

+ 15 - 0
Jint.Tests.Test262/BuiltIns/AnnexB/UnescapeTests.cs

@@ -0,0 +1,15 @@
+using Xunit;
+
+namespace Jint.Tests.Test262.BuiltIns.AnnexB
+{
+    public class UnescapeTests : Test262Test
+    {
+        [Theory(DisplayName = "annexB\\built-ins\\unescape")]
+        [MemberData(nameof(SourceFiles), "annexB\\built-ins\\unescape", false)]
+        [MemberData(nameof(SourceFiles), "annexB\\built-ins\\unescape", true, Skip = "Skipped")]
+        protected void RunTest(SourceFile sourceFile)
+        {
+            RunTestInternal(sourceFile);
+        }
+    }
+}

+ 19 - 0
Jint.Tests/Runtime/GlobalTests.cs

@@ -0,0 +1,19 @@
+using Xunit;
+
+namespace Jint.Tests.Runtime
+{
+    public class GlobalTests
+    {
+        [Fact]
+        public void UnescapeAtEndOfString()
+        {
+            var e = new Engine();
+
+            Assert.Equal("@", e.Execute("unescape('%40');").GetCompletionValue().AsString());
+            Assert.Equal("@_", e.Execute("unescape('%40_');").GetCompletionValue().AsString());
+            Assert.Equal("@@", e.Execute("unescape('%40%40');").GetCompletionValue().AsString());
+            Assert.Equal("@", e.Execute("unescape('%u0040');").GetCompletionValue().AsString());
+            Assert.Equal("@@", e.Execute("unescape('%u0040%u0040');").GetCompletionValue().AsString());
+        }
+    }
+}

+ 4 - 4
Jint/Native/Global/GlobalObject.cs

@@ -66,8 +66,8 @@ namespace Jint.Native.Global
                 ["decodeURIComponent"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "decodeURIComponent", DecodeUriComponent, 1, lengthFlags), propertyFlags),
                 ["encodeURI"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "encodeURI", EncodeUri, 1, lengthFlags), propertyFlags),
                 ["encodeURIComponent"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "encodeURIComponent", EncodeUriComponent, 1, lengthFlags), propertyFlags),
-                ["escape"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "escape", Escape, 1), propertyFlags),
-                ["unescape"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "unescape", Unescape, 1), propertyFlags),
+                ["escape"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "escape", Escape, 1, lengthFlags), propertyFlags),
+                ["unescape"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "unescape", Unescape, 1, lengthFlags), propertyFlags),
                 ["globalThis"] = new PropertyDescriptor(this, propertyFlags),
 
                 // toString is not mentioned or actually required in spec, but some tests rely on it
@@ -679,7 +679,7 @@ namespace Jint.Native.Global
                 var c = uriString[k];
                 if (c == '%')
                 {
-                    if (k < strLen - 6
+                    if (k <= strLen - 6
                         && uriString[k + 1] == 'u'
                         && uriString.Skip(k + 2).Take(4).All(IsValidHexaChar))
                     {
@@ -689,7 +689,7 @@ namespace Jint.Native.Global
 
                         k += 5;
                     }
-                    else if (k < strLen - 3
+                    else if (k <= strLen - 3
                         && uriString.Skip(k + 1).Take(2).All(IsValidHexaChar))
                     {
                         c = (char)int.Parse(