From 7afc70de404b6e5573f4e0b89e0e4a56bb10dda0 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sun, 5 Mar 2017 06:15:00 -0500 Subject: [PATCH 1/2] url: remove invalid file protocol check 'file' should have been 'file:' but since the WHATWG URL spec suggests using an opaque origin (which is what was already being used for file URLs), we'll just keep using that, making this merely a cleanup. PR-URL: https://github.com/nodejs/node/pull/11691 Reviewed-By: Luigi Pinca Reviewed-By: Joyee Cheung Reviewed-By: Timothy Gu Reviewed-By: Daijiro Wachi Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- lib/internal/url.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 6e6cc62226766b..7e53ac1dc2d7ba 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1112,7 +1112,6 @@ function originFor(url, base) { case 'https:': case 'ws:': case 'wss:': - case 'file': origin = new TupleOrigin(protocol.slice(0, -1), url[context].host, url[context].port, From e4fbd8e244cafa4bbb76aeac52c96941156f61d6 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sun, 5 Mar 2017 06:17:29 -0500 Subject: [PATCH 2/2] test: add more WHATWG URL origin tests PR-URL: https://github.com/nodejs/node/pull/11691 Reviewed-By: Luigi Pinca Reviewed-By: Joyee Cheung Reviewed-By: Timothy Gu Reviewed-By: Daijiro Wachi Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-whatwg-url-properties.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/parallel/test-whatwg-url-properties.js b/test/parallel/test-whatwg-url-properties.js index b5b3119422e668..c5d60229a9f2c1 100644 --- a/test/parallel/test-whatwg-url-properties.js +++ b/test/parallel/test-whatwg-url-properties.js @@ -142,3 +142,19 @@ assert.strictEqual(url.searchParams, oldParams); assert.strictEqual(opts.search, '?l=24'); assert.strictEqual(opts.hash, '#test'); } + +// Test special origins +[ + { 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: 'file:///tmp/mock/path' }, + { expected: 'null', url: 'npm://nodejs/rules' } +].forEach((test) => { + assert.strictEqual(new URL(test.url).origin, test.expected); +});