From 0d08d5ae7c2e6175b268e2c17a4d835ff8f9f6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sat, 9 May 2020 15:59:43 +0200 Subject: [PATCH] url: remove gopher from special schemes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/nodejs/node/issues/33315 Refs: https://github.com/whatwg/url/commit/d589670451a4da9717bad69ed5d5364f93fede33 Refs: https://github.com/whatwg/url/commit/7ae1c691c96f0d82fafa24c33aa1e8df9ffbf2bc PR-URL: https://github.com/nodejs/node/pull/33325 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- doc/api/url.md | 22 +++++++- lib/internal/url.js | 1 - src/env.h | 1 - src/node_url.cc | 1 - test/fixtures/wpt/README.md | 2 +- test/fixtures/wpt/url/failure.html | 1 + .../wpt/url/resources/setters_tests.json | 8 +-- .../wpt/url/resources/urltestdata.json | 50 +++++++++---------- test/fixtures/wpt/versions.json | 2 +- .../test-whatwg-url-custom-properties.js | 2 +- 10 files changed, 53 insertions(+), 37 deletions(-) diff --git a/doc/api/url.md b/doc/api/url.md index 49dcfbb418bb4f..3687ca73c53bf9 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -242,6 +242,13 @@ If the value assigned to the `href` property is not a valid URL, a `TypeError` will be thrown. #### `url.origin` + * {string} @@ -305,6 +312,12 @@ to percent-encode may vary somewhat from what the [`url.parse()`][] and [`url.format()`][] methods would produce. #### `url.port` + * {string} @@ -322,7 +335,6 @@ the protocol/scheme: | -------- | ---- | | "ftp" | 21 | | "file" | | -| "gopher" | 70 | | "http" | 80 | | "https" | 443 | | "ws" | 80 | @@ -407,6 +419,12 @@ console.log(myURL.href); Invalid URL protocol values assigned to the `protocol` property are ignored. ##### Special Schemes + The [WHATWG URL Standard][] considers a handful of URL protocol schemes to be _special_ in terms of how they are parsed and serialized. When a URL is @@ -444,7 +462,7 @@ console.log(u.href); ``` According to the WHATWG URL Standard, special protocol schemes are `ftp`, -`file`, `gopher`, `http`, `https`, `ws`, and `wss`. +`file`, `http`, `https`, `ws`, and `wss`. #### `url.search` diff --git a/lib/internal/url.js b/lib/internal/url.js index c0b8c17d098708..7c2637246e9b51 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -472,7 +472,6 @@ ObjectDefineProperties(URL.prototype, { } return kOpaqueOrigin; case 'ftp:': - case 'gopher:': case 'http:': case 'https:': case 'ws:': diff --git a/src/env.h b/src/env.h index dafb59c0460455..4b8670de46a8c2 100644 --- a/src/env.h +++ b/src/env.h @@ -371,7 +371,6 @@ constexpr size_t kFsStatsBufferLength = V(unknown_string, "") \ V(url_special_ftp_string, "ftp:") \ V(url_special_file_string, "file:") \ - V(url_special_gopher_string, "gopher:") \ V(url_special_http_string, "http:") \ V(url_special_https_string, "https:") \ V(url_special_ws_string, "ws:") \ diff --git a/src/node_url.cc b/src/node_url.cc index a181d5fb5d8d7c..b1b21a8ad3c0c0 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -726,7 +726,6 @@ std::string PercentDecode(const char* input, size_t len) { #define SPECIALS(XX) \ XX(ftp, 21, "ftp:") \ XX(file, -1, "file:") \ - XX(gopher, 70, "gopher:") \ XX(http, 80, "http:") \ XX(https, 443, "https:") \ XX(ws, 80, "ws:") \ diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 041e8fe1f2eec3..db10cdaf87fa86 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -12,7 +12,7 @@ Last update: - console: https://github.com/web-platform-tests/wpt/tree/9786a4b131/console - encoding: https://github.com/web-platform-tests/wpt/tree/5059d2c777/encoding -- url: https://github.com/web-platform-tests/wpt/tree/418f7fabeb/url +- url: https://github.com/web-platform-tests/wpt/tree/43feb7f612/url - resources: https://github.com/web-platform-tests/wpt/tree/e1fddfbf80/resources - interfaces: https://github.com/web-platform-tests/wpt/tree/8ada332aea/interfaces - html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing diff --git a/test/fixtures/wpt/url/failure.html b/test/fixtures/wpt/url/failure.html index 13a90cc8d097c1..bebdb3dcc4df6b 100644 --- a/test/fixtures/wpt/url/failure.html +++ b/test/fixtures/wpt/url/failure.html @@ -1,6 +1,7 @@ Test URL parser failure consistency +
diff --git a/test/fixtures/wpt/url/resources/setters_tests.json b/test/fixtures/wpt/url/resources/setters_tests.json index db23d924732800..6b7d19b10164a3 100644 --- a/test/fixtures/wpt/url/resources/setters_tests.json +++ b/test/fixtures/wpt/url/resources/setters_tests.json @@ -122,7 +122,7 @@ "href": "gopher://example.net:1234", "new_value": "file", "expected": { - "href": "gopher://example.net:1234/", + "href": "gopher://example.net:1234", "protocol": "gopher:" } }, @@ -212,7 +212,7 @@ }, { "href": "ssh://me@example.net", - "new_value": "gopher", + "new_value": "https", "expected": { "href": "ssh://me@example.net", "protocol": "ssh:" @@ -597,7 +597,7 @@ } }, { - "comment": "Cannot-be-a-base means no password", + "comment": "Cannot-be-a-base means no host", "href": "data:text/plain,Stuff", "new_value": "example.net", "expected": { @@ -1074,7 +1074,7 @@ } }, { - "comment": "Cannot-be-a-base means no password", + "comment": "Cannot-be-a-base means no host", "href": "data:text/plain,Stuff", "new_value": "example.net", "expected": { diff --git a/test/fixtures/wpt/url/resources/urltestdata.json b/test/fixtures/wpt/url/resources/urltestdata.json index 58501e215318df..61249e14996297 100644 --- a/test/fixtures/wpt/url/resources/urltestdata.json +++ b/test/fixtures/wpt/url/resources/urltestdata.json @@ -1076,15 +1076,15 @@ { "input": "gopher:/example.com/", "base": "http://example.org/foo/bar", - "href": "gopher://example.com/", - "origin": "gopher://example.com", + "href": "gopher:/example.com/", + "origin": "null", "protocol": "gopher:", "username": "", "password": "", - "host": "example.com", - "hostname": "example.com", + "host": "", + "hostname": "", "port": "", - "pathname": "/", + "pathname": "/example.com/", "search": "", "hash": "" }, @@ -1241,15 +1241,15 @@ { "input": "gopher:example.com/", "base": "http://example.org/foo/bar", - "href": "gopher://example.com/", - "origin": "gopher://example.com", + "href": "gopher:example.com/", + "origin": "null", "protocol": "gopher:", "username": "", "password": "", - "host": "example.com", - "hostname": "example.com", + "host": "", + "hostname": "", "port": "", - "pathname": "/", + "pathname": "example.com/", "search": "", "hash": "" }, @@ -2511,14 +2511,14 @@ { "input": "gopher://foo:70/", "base": "about:blank", - "href": "gopher://foo/", - "origin": "gopher://foo", + "href": "gopher://foo:70/", + "origin": "null", "protocol": "gopher:", "username": "", "password": "", - "host": "foo", + "host": "foo:70", "hostname": "foo", - "port": "", + "port": "70", "pathname": "/", "search": "", "hash": "" @@ -2527,7 +2527,7 @@ "input": "gopher://foo:443/", "base": "about:blank", "href": "gopher://foo:443/", - "origin": "gopher://foo:443", + "origin": "null", "protocol": "gopher:", "username": "", "password": "", @@ -2750,15 +2750,15 @@ { "input": "gopher:/example.com/", "base": "about:blank", - "href": "gopher://example.com/", - "origin": "gopher://example.com", + "href": "gopher:/example.com/", + "origin": "null", "protocol": "gopher:", "username": "", "password": "", - "host": "example.com", - "hostname": "example.com", + "host": "", + "hostname": "", "port": "", - "pathname": "/", + "pathname": "/example.com/", "search": "", "hash": "" }, @@ -2915,15 +2915,15 @@ { "input": "gopher:example.com/", "base": "about:blank", - "href": "gopher://example.com/", - "origin": "gopher://example.com", + "href": "gopher:example.com/", + "origin": "null", "protocol": "gopher:", "username": "", "password": "", - "host": "example.com", - "hostname": "example.com", + "host": "", + "hostname": "", "port": "", - "pathname": "/", + "pathname": "example.com/", "search": "", "hash": "" }, diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 566041b6362862..047ac440d8e5d7 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -8,7 +8,7 @@ "path": "encoding" }, "url": { - "commit": "418f7fabebeeb642e79e05b48ffde1a601c7e058", + "commit": "43feb7f612fe9160639e09a47933a29834904d69", "path": "url" }, "resources": { diff --git a/test/parallel/test-whatwg-url-custom-properties.js b/test/parallel/test-whatwg-url-custom-properties.js index 23742a8e7493e2..3a9ae43f1a4d74 100644 --- a/test/parallel/test-whatwg-url-custom-properties.js +++ b/test/parallel/test-whatwg-url-custom-properties.js @@ -171,11 +171,11 @@ assert.strictEqual(url.searchParams, oldParams); { expected: 'https://whatwg.org', url: 'blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f' }, { expected: 'ftp://example.org', url: 'ftp://example.org/foo' }, - { expected: 'gopher://gopher.quux.org', url: 'gopher://gopher.quux.org/1/' }, { expected: 'http://example.org', url: 'http://example.org/foo' }, { expected: 'https://example.org', url: 'https://example.org/foo' }, { expected: 'ws://example.org', url: 'ws://example.org/foo' }, { expected: 'wss://example.org', url: 'wss://example.org/foo' }, + { expected: 'null', url: 'gopher://gopher.quux.org/1/' }, { expected: 'null', url: 'file:///tmp/mock/path' }, { expected: 'null', url: 'npm://nodejs/rules' } ].forEach((test) => {