Skip to content

Commit

Permalink
fixing absoluteTo() to properly resolve relative scheme - closes #73
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Apr 2, 2013
1 parent 324c9ea commit 4a85824
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 8 additions & 4 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4a85824

Please sign in to comment.