From 1cc30ee19a6874ba763360e28d5984fd551ab047 Mon Sep 17 00:00:00 2001 From: Chen Date: Tue, 28 Feb 2017 04:22:06 +0800 Subject: [PATCH] fix(absoluteTo): return original URI for URI with scheme closes #328 #329 --- src/URI.js | 5 ++++- test/test.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/URI.js b/src/URI.js index 0f023981..d8492ecc 100644 --- a/src/URI.js +++ b/src/URI.js @@ -2077,7 +2077,10 @@ base = new URI(base); } - if (!resolved._parts.protocol) { + if (resolved._parts.protocol) { + // Directly returns even if this._parts.hostname is empty. + return resolved; + } else { resolved._parts.protocol = base._parts.protocol; } diff --git a/test/test.js b/test/test.js index 8745d608..dc07acf0 100644 --- a/test/test.js +++ b/test/test.js @@ -1342,6 +1342,16 @@ url: 'http://github.com//the_relative_url', base: 'http://example.com/foo/bar', result: 'http://github.com//the_relative_url' + }, { + name: 'absolute passthru - file:/// - urljoin (#328)', + url: 'file:///C:/skyclan/snipkit', + base: 'http://example.com/foo/bar', + result: 'file:///C:/skyclan/snipkit' + }, { + name: 'absolute passthru - generic empty-hostname - urljoin (#328)', + url: 'http:///foo', + base: 'http://example.com/foo/bar', + result: 'http:///foo' }, { name: 'file paths - urljoin', url: 'anotherFile',