Permalink
Browse files

Fix #href being screwed up when an URI is passed into itself.

  • Loading branch information...
1 parent 9819240 commit 4b77da37c1a594bc3a1c60678b41e47f15851d0a @slaskis slaskis committed May 22, 2011
Showing with 7 additions and 5 deletions.
  1. +1 −2 lib/addressable.js
  2. +6 −3 test/test-addressable.js
View
3 lib/addressable.js
@@ -129,8 +129,7 @@ var KNOWN_PORTS = {
* @return An URI object. Or null if the href is not an parsable uri.
*/
URI.parse = function(href){
- if( typeof href !== "string" )
- href = URI.format(href);
+ href = URI.format(href);
var md = RE_URI.exec(href);
if( md ){
var uri = new URI();
View
9 test/test-addressable.js
@@ -7,12 +7,15 @@ exports["an empty string"] = function(){
}
exports["an addressable.URI is parsed to itself"] = function(){
- var uri1 = addressable.parse("http://www.example.com/hej/test.html?query=bula&another=bula#anchored");
- assert.ok( uri1 instanceof addressable.URI, "should be an URI instance" )
+ var url = "http://api.twitter.com/1/statuses/show/60697562776219650.json";
+ var uri1 = addressable.parse(url);
var uri2 = addressable.parse(uri1);
+ assert.ok( uri1 instanceof addressable.URI, "should be an URI instance" )
assert.ok( uri2 instanceof addressable.URI, "should be an URI instance" )
+ assert.equal( uri1.href, url )
assert.notEqual( uri1, uri2, "should not be the same instance." )
- assert.equal( uri1.toString(), uri2.toString(), "should be the same URI string." )
+ assert.equal( uri1.toString(), uri2.toString())
+ assert.equal( uri1.toString(), url)
}
exports["also accepts nodes built-in URL"] = function(){

0 comments on commit 4b77da3

Please sign in to comment.