Skip to content

Commit

Permalink
Merge Pull Request #77 - accept new URI(<a>)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Aug 2, 2013
2 parents b8487d1 + 7b186ca commit 07ba035
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ p.href = function(href, build) {
this._parts = URI._parts();

var _URI = href instanceof URI;
var _object = typeof href === "object" && (href.hostname || href.path);
var _object = typeof href === "object" && (href.hostname || href.path || href.pathname);


// window.location is reported to be an object, but it's not the sort
Expand Down
20 changes: 17 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@ test("new URI(object)", function() {
var u = new URI({protocol: "http", hostname: 'example.org'});
ok(u instanceof URI, "instanceof URI");
ok(u._parts.hostname !== undefined, "host undefined");

u = new URI(location);
});
test("new URI(Location)", function () {
var u = new URI(location);
equal(u.href(), String(location.href), "location object");
});
test("new URI(HTMLAnchorElement", function (){
var a = document.createElement("a");
a.href = "http://example.org/foobar.html";
var u = new URI(a);
equal(u.scheme(), "http", "scheme");
equal(u.host(), "example.org", "host");
equal(u.path(), "/foobar.html", "path");

a.href = "file:///C:/foo/bar.html";
u = new URI(a);
equal(u.href(), a.href, "file");
});
test("new URI(URI)", function() {
var u = new URI(new URI({protocol: "http", hostname: 'example.org'}));
ok(u instanceof URI, "instanceof URI");
Expand All @@ -30,7 +43,8 @@ test("new URI(new Date())", function() {
test("new URI()", function() {
var u = new URI();
ok(u instanceof URI, "instanceof URI");
ok(u._parts.hostname === location.hostname, "hostname == location.hostname");
ok(u._parts.hostname === location.hostname || u._parts.hostname === null && location.hostname === '',
"hostname == location.hostname");
});
test("function URI(string)", function() {
var u = new URI("http://example.org/");
Expand Down

0 comments on commit 07ba035

Please sign in to comment.