Skip to content

Commit

Permalink
uri.path is now a setter.
Browse files Browse the repository at this point in the history
  • Loading branch information
slaskis committed May 1, 2011
1 parent c050128 commit 2bbff14
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -47,6 +47,10 @@

## History

### 0.3.1

* [Fix] `uri.path` is now also a setter.

### 0.3.0

* [Feature] What was previously `uri.path` is now `uri.pathname` and `uri.path` is now essentially `uri.pathname + uri.search` to match the HTTP.request API in Node 0.3.6+.
Expand Down
10 changes: 8 additions & 2 deletions lib/addressable.js
Expand Up @@ -87,8 +87,8 @@ function URI(){
return require("querystring").parse( this.querystring );
})

this.__defineSetter__("query",function(vals){
this.querystring = require("querystring").stringify( vals );
this.__defineSetter__("query",function(qs){
this.querystring = require("querystring").stringify(qs);
})

this.__defineGetter__("search",function(){
Expand All @@ -98,6 +98,12 @@ function URI(){
this.__defineGetter__("path",function(){
return this.pathname + this.search;
})

this.__defineSetter__("path",function(path){
var i = path.indexOf("?");
this.pathname = path.slice(0,i);
this.querystring = path.slice(i+1);
})
}

var PATH_SLASH_SCHEMES = ["http","https","ftp","tftp"];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "addressable",
"description": "A URI parsing module heavily inspired by Rubys Addressable gem",
"homepage": "http://github.com/publicclass/addressable",
"version": "0.3.0",
"version": "0.3.1",
"author": "Robert Sköld <robert@publicclass.se>",
"dependencies": {},
"keywords": ["addressable", "uri"],
Expand Down
6 changes: 6 additions & 0 deletions test/test-addressable.js
Expand Up @@ -23,6 +23,12 @@ exports["an (non-auth) HTTP URI"] = function(){
q.more = "bula";
http.query = q;
assert.equal(http.querystring,"query=bula&another=bula&more=bula","should be able to modify the query object.")

http.path = "/abc?q=123";
assert.equal(http.pathname, "/abc", "changing the path should update the pathname.")
assert.equal(http.querystring, "q=123", "changing the path should update the querystring.")
assert.equal(http.search, "?q=123", "changing the path should update the search.")
assert.eql(http.query, {q:123}, "changing the path should update the query.")
}

exports["an (authorized) IP HTTP URI"] = function(){
Expand Down

0 comments on commit 2bbff14

Please sign in to comment.