diff --git a/README.md b/README.md index 957e4ac6..bf8c596d 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,10 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m ## Changelog ## +### 1.10.1 (April 2nd 2013) ### + +* adding [`absoluteTo()`](http://medialize.github.com/URI.js/docs.html#absoluteto) - ([Issue #71](https://github.com/medialize/URI.js/issues/73)) + ### 1.10.0 (March 16th 2013) ### * adding [`hasQuery()`](http://medialize.github.com/URI.js/docs.html#search-has) - ([Issue #71](https://github.com/medialize/URI.js/issues/71)) diff --git a/src/URI.js b/src/URI.js index 87cb97dd..03bcce76 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1635,13 +1635,17 @@ p.absoluteTo = function(base) { throw new Error('URNs do not have any generally defined hierachical components'); } - if (this._parts.hostname) { - return resolved; - } - if (!(base instanceof URI)) { base = new URI(base); } + + if (!resolved._parts.protocol) { + resolved._parts.protocol = base._parts.protocol; + } + + if (this._parts.hostname) { + return resolved; + } for (i = 0, p; p = properties[i]; i++) { resolved._parts[p] = base._parts[p]; diff --git a/test/test.js b/test/test.js index e4f6cbc8..f8769e2b 100644 --- a/test/test.js +++ b/test/test.js @@ -897,6 +897,11 @@ test("absoluteTo", function() { url: '/absolute/path?blubber=1#hash3', base: 'http://user:pass@www.example.org:1234/path/to/file?some=query#hash', result: 'http://user:pass@www.example.org:1234/absolute/path?blubber=1#hash3' + }, { + name: 'absolute resolve full URL without scheme', + url: '//user:pass@www.example.org:1234/path/to/file?some=query#hash', + base: 'proto://user:pass@www.example.org:1234/path/to/file?some=query#hash', + result: 'proto://user:pass@www.example.org:1234/path/to/file?some=query#hash' }, { name: 'path-relative resolve', url: './relative/path?blubber=1#hash3',