Skip to content

Commit

Permalink
fixing absoluteTo() - Issue #29
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Jun 24, 2012
1 parent 3eb744d commit 9f71510
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,11 +1314,15 @@ p.absoluteTo = function(base) {
if (this._parts.urn) {
throw new Error('URNs do not have any generally defined hierachical components');
}

if (this._parts.hostname) {
return new URI(this);
}

if (!(base instanceof URI)) {
base = new URI(base);
}

var resolved = new URI(this),
properties = ['protocol', 'username', 'password', 'hostname', 'port'],
basedir;
Expand Down
21 changes: 7 additions & 14 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,37 +689,30 @@ test("absoluteTo", function() {
base: 'rel/path/something',
result: 'rel/path/the_relative_url'
}, {
name: 'relative path file - urljoin',
name: 'relative parent path file - urljoin',
url: '../the_relative_url',
base: 'rel/path/',
result: 'rel/the_relative_url'
}, {
name: 'relative path file - urljoin',
name: 'relative root path file - urljoin',
url: '/the_relative_url',
base: 'rel/path/',
result: '/the_relative_url'
}, {
name: 'relative path file - urljoin',
name: 'relative root file - urljoin',
url: '/the_relative_url',
base: 'http://example.com/rel/path/',
result: 'http://example.com/the_relative_url'
}, {
name: 'relative path file - urljoin',
url: '/the_relative_url',
base: 'http://github.com//the_relative_url',
// result is sanitized, so a double slashes are eradicated!
//result: 'http://github.com//the_relative_url'
result: 'http://github.com/the_relative_url'
name: 'absolute passthru - urljoin',
url: 'http://github.com//the_relative_url',
base: 'http://example.com/foo/bar',
result: 'http://github.com//the_relative_url'
}, {
name: 'file paths - urljoin',
url: 'anotherFile',
base: 'aFile',
result: 'anotherFile'
}, {
name: 'absolute URL to absolute URL',
url: 'http://example.com/some/other/path/file',
base: 'http://example.org/rel/path/foo',
result: 'http://example.org/some/other/path/file'
}
];

Expand Down

0 comments on commit 9f71510

Please sign in to comment.