diff --git a/src/client/sandbox/node/window.ts b/src/client/sandbox/node/window.ts index 4ae4d3b7f..0ff5289dd 100644 --- a/src/client/sandbox/node/window.ts +++ b/src/client/sandbox/node/window.ts @@ -385,19 +385,11 @@ export default class WindowSandbox extends SandboxBase { }; } - window.open = function () { - const newArgs = []; - const target = arguments[1] ? nodeSandbox.element.getTarget(null, arguments[1]) : '_self'; + window.open = function (...args) { + args[0] = getProxyUrl(args[0]); + args[1] = args[1] ? nodeSandbox.element.getTarget(null, String(args[1])) : '_self'; - newArgs.push(getProxyUrl(arguments[0])); - newArgs.push(target); - - if (arguments.length > 2) - newArgs.push(arguments[2]); - if (arguments.length > 3) - newArgs.push(arguments[3]); - - return nativeMethods.windowOpen.apply(window, newArgs); + return nativeMethods.windowOpen.apply(window, args); }; if (window.FontFace) { diff --git a/test/client/fixtures/target-attr-test.js b/test/client/fixtures/target-attr-test.js index 2c0ed1006..5254b57e9 100644 --- a/test/client/fixtures/target-attr-test.js +++ b/test/client/fixtures/target-attr-test.js @@ -104,6 +104,11 @@ test('change window name', function () { test('window.open', function () { var nativeWindowOpen = nativeMethods.windowOpen; var targets = []; + var iframe = document.createElement('iframe'); + + iframe.setAttribute('id', 'test' + Date.now()); + iframe.setAttribute('name', '2'); + document.body.appendChild(iframe); nativeMethods.windowOpen = function (url, target) { targets.push(target); @@ -114,15 +119,18 @@ test('window.open', function () { window.open('http://some-url.com/', 'window_name'); window.open('http://some-url.com/', 'unknow_name'); window.open('http://some-url.com/'); + window.open('http://some-url.com/', 2); - strictEqual(targets.length, 5); + strictEqual(targets.length, 6); strictEqual(targets[0], '_self'); strictEqual(targets[1], '_top'); strictEqual(targets[2], 'window_name'); strictEqual(targets[3], '_top'); strictEqual(targets[4], '_self'); + strictEqual(targets[5], '2'); nativeMethods.windowOpen = nativeWindowOpen; + document.body.removeChild(iframe); }); test('case insensitive target="_blank"', function () {