Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unescape at end of string #831

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Jint.Tests.Test262/BuiltIns/AnnexB/EscapeTests.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions Jint.Tests.Test262/BuiltIns/AnnexB/UnescapeTests.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions Jint.Tests/Runtime/GlobalTests.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
8 changes: 4 additions & 4 deletions Jint/Native/Global/GlobalObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ protected override void Initialize()
["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
Expand Down Expand Up @@ -679,7 +679,7 @@ public JsValue Unescape(JsValue thisObject, JsValue[] arguments)
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))
{
Expand All @@ -689,7 +689,7 @@ public JsValue Unescape(JsValue thisObject, JsValue[] arguments)

k += 5;
}
else if (k < strLen - 3
else if (k <= strLen - 3
&& uriString.Skip(k + 1).Take(2).All(IsValidHexaChar))
{
c = (char)int.Parse(
Expand Down