From 6ccbf38a4f3dfceb00be99960097b4166037207e Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Mon, 3 Apr 2017 17:48:32 +0900 Subject: [PATCH] test: synchronize WPT url setter test data Updates: + Bring tests url-setter-tests from WPT, and put it as JavaScript + Comment out unpassed tests Refs: https://github.com/w3c/web-platform-tests/pull/5112 Refs: https://github.com/nodejs/node/pull/11887 PR-URL: https://github.com/nodejs/node/pull/12058 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung Reviewed-By: Timothy Gu --- ...-setter-tests.json => url-setter-tests.js} | 545 +++++++++++++++++- test/parallel/test-whatwg-url-setters.js | 2 +- 2 files changed, 534 insertions(+), 13 deletions(-) rename test/fixtures/{url-setter-tests.json => url-setter-tests.js} (73%) diff --git a/test/fixtures/url-setter-tests.json b/test/fixtures/url-setter-tests.js similarity index 73% rename from test/fixtures/url-setter-tests.json rename to test/fixtures/url-setter-tests.js index d0138204b3fe6c..9b39d0bed67bfc 100644 --- a/test/fixtures/url-setter-tests.json +++ b/test/fixtures/url-setter-tests.js @@ -1,6 +1,12 @@ +'use strict'; + +/* WPT Refs: + https://github.com/w3c/web-platform-tests/blob/e48dd15/url/setters_tests.json + License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html +*/ +module.exports = { "comment": [ - "License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html", "## Tests for setters of https://url.spec.whatwg.org/#urlutils-members", "", "This file contains a JSON object.", @@ -40,6 +46,14 @@ "protocol": "b:" } }, + { + "href": "javascript:alert(1)", + "new_value": "defuse", + "expected": { + "href": "defuse:alert(1)", + "protocol": "defuse:" + } + }, { "comment": "Upper-case ASCII is lower-cased", "href": "a://example.net", @@ -103,11 +117,11 @@ } }, { - "comment": "Can’t switch from special scheme to non-special", - "href": "http://example.net", - "new_value": "b", + "comment": "Can’t switch from URL containing username/password/port to file", + "href": "http://test@example.net", + "new_value": "file", "expected": { - "href": "http://example.net/", + "href": "http://test@example.net/", "protocol": "http:" } }, @@ -152,6 +166,15 @@ "protocol": "file:" } }, + { + "comment": "Can’t switch from special scheme to non-special", + "href": "http://example.net", + "new_value": "b", + "expected": { + "href": "http://example.net/", + "protocol": "http:" + } + }, { "href": "file://hi/path", "new_value": "s", @@ -265,6 +288,14 @@ "username": "" } }, + { + "href": "javascript:alert(1)", + "new_value": "wario", + "expected": { + "href": "javascript:alert(1)", + "username": "" + } + }, { "href": "http://example.net", "new_value": "me", @@ -314,7 +345,31 @@ "href": "http://%c3%89t%C3%A9@example.net/", "username": "%c3%89t%C3%A9" } - } + }, + { + "href": "sc:///", + "new_value": "x", + "expected": { + "href": "sc:///", + "username": "" + } + }, + { + "href": "javascript://x/", + "new_value": "wario", + "expected": { + "href": "javascript://wario@x/", + "username": "wario" + } + }, + // { + // "href": "file://test/", + // "new_value": "test", + // "expected": { + // "href": "file://test/", + // "username": "" + // } + // } ], "password": [ { @@ -393,9 +448,134 @@ "href": "http://:%c3%89t%C3%A9@example.net/", "password": "%c3%89t%C3%A9" } - } + }, + { + "href": "sc:///", + "new_value": "x", + "expected": { + "href": "sc:///", + "password": "" + } + }, + { + "href": "javascript://x/", + "new_value": "bowser", + "expected": { + "href": "javascript://:bowser@x/", + "password": "bowser" + } + }, + // { + // "href": "file://test/", + // "new_value": "test", + // "expected": { + // "href": "file://test/", + // "password": "" + // } + // } ], "host": [ + { + "comment": "Non-special scheme", + "href": "sc://x/", + "new_value": "\u0000", + "expected": { + "href": "sc://x/", + "host": "x", + "hostname": "x" + } + }, + // { + // "href": "sc://x/", + // "new_value": "\u0009", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "\u000A", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "\u000D", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + { + "href": "sc://x/", + "new_value": " ", + "expected": { + "href": "sc://x/", + "host": "x", + "hostname": "x" + } + }, + // { + // "href": "sc://x/", + // "new_value": "#", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "/", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "?", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + { + "href": "sc://x/", + "new_value": "@", + "expected": { + "href": "sc://x/", + "host": "x", + "hostname": "x" + } + }, + // { + // "href": "sc://x/", + // "new_value": "ß", + // "expected": { + // "href": "sc://%C3%9F/", + // "host": "%C3%9F", + // "hostname": "%C3%9F" + // } + // }, + { + "comment": "IDNA Nontransitional_Processing", + "href": "https://x/", + "new_value": "ß", + "expected": { + "href": "https://xn--zca/", + "host": "xn--zca", + "hostname": "xn--zca" + } + }, { "comment": "Cannot-be-a-base means no host", "href": "mailto:me@example.net", @@ -617,7 +797,7 @@ } }, { - "comment": "\\ is not a delimiter for non-special schemes, and it’s invalid in a domain", + "comment": "\\ is not a delimiter for non-special schemes, but still forbidden in hosts", "href": "view-source+http://example.net/path", "new_value": "example.com\\stuff", "expected": { @@ -681,9 +861,187 @@ "hostname": "example.com", "port": "" } - } + }, + { + "comment": "Broken IPv6", + "href": "http://example.net/", + "new_value": "[google.com]", + "expected": { + "href": "http://example.net/", + "host": "example.net", + "hostname": "example.net" + } + }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.2.3.4x]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.2.3.]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.2.]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "file://y/", + // "new_value": "x:123", + // "expected": { + // "href": "file://y/", + // "host": "y", + // "hostname": "y", + // "port": "" + // } + // }, + // { + // "href": "file://y/", + // "new_value": "loc%41lhost", + // "expected": { + // "href": "file:///", + // "host": "", + // "hostname": "", + // "port": "" + // } + // }, + // { + // "href": "file://hi/x", + // "new_value": "", + // "expected": { + // "href": "file:///x", + // "host": "", + // "hostname": "", + // "port": "" + // } + // }, + // { + // "href": "sc://test@test/", + // "new_value": "", + // "expected": { + // "href": "sc://test@test/", + // "host": "test", + // "hostname": "test", + // "username": "test" + // } + // }, + // { + // "href": "sc://test:12/", + // "new_value": "", + // "expected": { + // "href": "sc://test:12/", + // "host": "test:12", + // "hostname": "test", + // "port": "12" + // } + // } ], "hostname": [ + { + "comment": "Non-special scheme", + "href": "sc://x/", + "new_value": "\u0000", + "expected": { + "href": "sc://x/", + "host": "x", + "hostname": "x" + } + }, + // { + // "href": "sc://x/", + // "new_value": "\u0009", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "\u000A", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "\u000D", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + { + "href": "sc://x/", + "new_value": " ", + "expected": { + "href": "sc://x/", + "host": "x", + "hostname": "x" + } + }, + // { + // "href": "sc://x/", + // "new_value": "#", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "/", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + // { + // "href": "sc://x/", + // "new_value": "?", + // "expected": { + // "href": "sc:///", + // "host": "", + // "hostname": "" + // } + // }, + { + "href": "sc://x/", + "new_value": "@", + "expected": { + "href": "sc://x/", + "host": "x", + "hostname": "x" + } + }, { "comment": "Cannot-be-a-base means no host", "href": "mailto:me@example.net", @@ -828,7 +1186,7 @@ } }, { - "comment": "\\ is not a delimiter for non-special schemes, and it’s invalid in a domain", + "comment": "\\ is not a delimiter for non-special schemes, but still forbidden in hosts", "href": "view-source+http://example.net/path", "new_value": "example.com\\stuff", "expected": { @@ -837,7 +1195,103 @@ "hostname": "example.net", "port": "" } - } + }, + { + "comment": "Broken IPv6", + "href": "http://example.net/", + "new_value": "[google.com]", + "expected": { + "href": "http://example.net/", + "host": "example.net", + "hostname": "example.net" + } + }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.2.3.4x]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.2.3.]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.2.]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "http://example.net/", + // "new_value": "[::1.]", + // "expected": { + // "href": "http://example.net/", + // "host": "example.net", + // "hostname": "example.net" + // } + // }, + // { + // "href": "file://y/", + // "new_value": "x:123", + // "expected": { + // "href": "file://y/", + // "host": "y", + // "hostname": "y", + // "port": "" + // } + // }, + // { + // "href": "file://y/", + // "new_value": "loc%41lhost", + // "expected": { + // "href": "file:///", + // "host": "", + // "hostname": "", + // "port": "" + // } + // }, + // { + // "href": "file://hi/x", + // "new_value": "", + // "expected": { + // "href": "file:///x", + // "host": "", + // "hostname": "", + // "port": "" + // } + // }, + // { + // "href": "sc://test@test/", + // "new_value": "", + // "expected": { + // "href": "sc://test@test/", + // "host": "test", + // "hostname": "test", + // "username": "test" + // } + // }, + // { + // "href": "sc://test:12/", + // "new_value": "", + // "expected": { + // "href": "sc://test:12/", + // "host": "test:12", + // "hostname": "test", + // "port": "12" + // } + // } ], "port": [ { @@ -992,6 +1446,65 @@ "hostname": "example.net", "port": "8080" } + }, + { + "comment": "Port numbers are 16 bit integers, overflowing is an error", + "href": "non-special://example.net:8080/path", + "new_value": "65536", + "expected": { + "href": "non-special://example.net:8080/path", + "host": "example.net:8080", + "hostname": "example.net", + "port": "8080" + } + }, + { + "href": "file://test/", + "new_value": "12", + "expected": { + "href": "file://test/", + "port": "" + } + }, + { + "href": "file://localhost/", + "new_value": "12", + "expected": { + "href": "file:///", + "port": "" + } + }, + { + "href": "non-base:value", + "new_value": "12", + "expected": { + "href": "non-base:value", + "port": "" + } + }, + { + "href": "sc:///", + "new_value": "12", + "expected": { + "href": "sc:///", + "port": "" + } + }, + { + "href": "sc://x/", + "new_value": "12", + "expected": { + "href": "sc://x:12/", + "port": "12" + } + }, + { + "href": "javascript://x/", + "new_value": "12", + "expected": { + "href": "javascript://x:12/", + "port": "12" + } } ], "pathname": [ @@ -1224,6 +1737,14 @@ "href": "http://example.net/#%c3%89t%C3%A9", "hash": "#%c3%89t%C3%A9" } - } + }, + // { + // "href": "javascript:alert(1)", + // "new_value": "castle", + // "expected": { + // "href": "javascript:alert(1)#castle", + // "hash": "#castle" + // } + // } ] } diff --git a/test/parallel/test-whatwg-url-setters.js b/test/parallel/test-whatwg-url-setters.js index 409ed1bd00d36c..63ebba84918945 100644 --- a/test/parallel/test-whatwg-url-setters.js +++ b/test/parallel/test-whatwg-url-setters.js @@ -12,7 +12,7 @@ if (!common.hasIntl) { } const request = { - response: require(path.join(common.fixturesDir, 'url-setter-tests.json')) + response: require(path.join(common.fixturesDir, 'url-setter-tests')) }; /* eslint-disable */