From 9d4d73ffa9ac1b6d4fc288d09ddb9046630c1e40 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Fri, 17 Mar 2017 03:41:54 +0100 Subject: [PATCH 1/2] url: restrict setting protocol to "file" Since file URLs can not have `username/password/port`, the specification was updated to restrict setting protocol to "file". Refs: https://github.com/whatwg/url/pull/269 Fixes: https://github.com/nodejs/node/issues/11785 --- lib/internal/url.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/internal/url.js b/lib/internal/url.js index 005f5b66476752..91b0640b50e8f6 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -133,6 +133,13 @@ function onParseProtocolComplete(flags, protocol, username, password, if ((s && !newIsSpecial) || (!s && newIsSpecial)) { return; } + if (protocol === 'file:' && + (ctx.username || ctx.password || ctx.port !== undefined)) { + return; + } + if (ctx.scheme === 'file:' && !ctx.host) { + return; + } if (newIsSpecial) { ctx.flags |= binding.URL_FLAGS_SPECIAL; } else { From 18eebe979244f052d04c5f0af22baf1d0dca7fc6 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Fri, 17 Mar 2017 01:49:58 +0100 Subject: [PATCH 2/2] test: synchronize WPT url setters tests data Synchronize url-setter-test to upstream. Refs: https://github.com/w3c/web-platform-tests/pull/5112 --- test/fixtures/url-setter-tests.json | 51 ++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/test/fixtures/url-setter-tests.json b/test/fixtures/url-setter-tests.json index 4876b9940c1d98..d0138204b3fe6c 100644 --- a/test/fixtures/url-setter-tests.json +++ b/test/fixtures/url-setter-tests.json @@ -111,6 +111,55 @@ "protocol": "http:" } }, + { + "href": "gopher://example.net:1234", + "new_value": "file", + "expected": { + "href": "gopher://example.net:1234/", + "protocol": "gopher:" + } + }, + { + "href": "wss://x:x@example.net:1234", + "new_value": "file", + "expected": { + "href": "wss://x:x@example.net:1234/", + "protocol": "wss:" + } + }, + { + "comment": "Can’t switch from file URL with no host", + "href": "file://localhost/", + "new_value": "http", + "expected": { + "href": "file:///", + "protocol": "file:" + } + }, + { + "href": "file:///test", + "new_value": "gopher", + "expected": { + "href": "file:///test", + "protocol": "file:" + } + }, + { + "href": "file:", + "new_value": "wss", + "expected": { + "href": "file:///", + "protocol": "file:" + } + }, + { + "href": "file://hi/path", + "new_value": "s", + "expected": { + "href": "file://hi/path", + "protocol": "file:" + } + }, { "href": "https://example.net", "new_value": "s", @@ -1177,4 +1226,4 @@ } } ] -} \ No newline at end of file +}