Skip to content

Commit

Permalink
#3, fixed query to search
Browse files Browse the repository at this point in the history
  • Loading branch information
hotoo committed Mar 29, 2014
1 parent bcb036c commit bbe8877
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/url.js
@@ -1,6 +1,6 @@
define(function(require, exports, module) {

// 2.protocol 4.username 5.password 7.hostname 8.port 9.path 10.query 11.hash
// 2.protocol 4.username 5.password 7.hostname 8.port 9.path 10.search 11.hash
// | | | | | | | |
// ------ ----- ------ ----------- ----- ----------- --------- -----
var RE_URL = /^((?:(\w+:)\/\/)?((\w+):?(\w+)?@)?(([^\/\?:]+)(?:\:(\d+))?))(\/[^\?#]+)?(\?[^#]+)?(#.*)?/;
Expand Down Expand Up @@ -33,8 +33,8 @@ define(function(require, exports, module) {
this.hostname = u[7];
this.port = u[8] || DEFAULT_PORT[this.protocol] || "";
this.path = u[9] || "/";
this.query = u[10] || "";
this._query = parseQuery(this.query);
this.search = u[10] || "";
this._query = parseQuery(this.search);
this.hash = u[11] || "";
};

Expand Down Expand Up @@ -109,7 +109,7 @@ define(function(require, exports, module) {
Url.prototype.delParam = function(name){
try{
delete this._query[name];
this.query = makeQueryString(this._query);
this.search = makeQueryString(this._query);
}catch(ex){}
return this;
};
Expand All @@ -121,7 +121,7 @@ define(function(require, exports, module) {
Url.prototype.setParam = function(name, value){
if(!isArray(value)){value = [value];}
this._query[name] = value;
this.query = makeQueryString(this._query);
this.search = makeQueryString(this._query);
return this;
};

Expand All @@ -136,15 +136,15 @@ define(function(require, exports, module) {
}else{
this._query[name] = value;
}
this.query = makeQueryString(this._query);
this.search = makeQueryString(this._query);
return this;
};

// Clear all param datas.
// @return {Url} this.
Url.prototype.clearParams = function(){
this._query = {};
this.query = makeQueryString(this._query);
this.search = makeQueryString(this._query);
return this;
};

Expand Down
14 changes: 7 additions & 7 deletions tests/url-spec.js
Expand Up @@ -12,7 +12,7 @@ define(function(require) {
hostname: "www.example.com",
port: "80",
path: "/",
query: "",
search: "",
hash: ""
}],
["http://www.example.com/", {
Expand All @@ -21,7 +21,7 @@ define(function(require) {
hostname: "www.example.com",
port: "80",
path: "/",
query: "",
search: "",
hash: ""
}],
["https://www.example.com/path/to/page.html", {
Expand All @@ -30,7 +30,7 @@ define(function(require) {
hostname: "www.example.com",
port: "443",
path: "/path/to/page.html",
query: "",
search: "",
hash: ""
}],
["http://www.example.com:8080/path/to/page.html?abc=A1&abc=A2", {
Expand All @@ -39,7 +39,7 @@ define(function(require) {
hostname: "www.example.com",
port: "8080",
path: "/path/to/page.html",
query: "?abc=A1&abc=A2",
search: "?abc=A1&abc=A2",
hash: ""
}],
["http://user@www.example.com:8080/path/to/page.html?abc=A1&abc=A2#hash", {
Expand All @@ -50,7 +50,7 @@ define(function(require) {
hostname: "www.example.com",
port: "8080",
path: "/path/to/page.html",
query: "?abc=A1&abc=A2",
search: "?abc=A1&abc=A2",
hash: "#hash"
}],
["http://user:pass@www.example.com:8080/path/to/page.html?abc=A1&abc=A2#hash", {
Expand All @@ -61,7 +61,7 @@ define(function(require) {
hostname: "www.example.com",
port: "8080",
path: "/path/to/page.html",
query: "?abc=A1&abc=A2",
search: "?abc=A1&abc=A2",
hash: "#hash"
}],
];
Expand All @@ -80,7 +80,7 @@ define(function(require) {
expect(url.hostname).to.equal(r.hostname);
expect(url.port).to.equal(r.port);
expect(url.path).to.equal(r.path);
expect(url.query).to.equal(r.query);
expect(url.search).to.equal(r.search);
expect(url.hash).to.equal(r.hash);

});
Expand Down

0 comments on commit bbe8877

Please sign in to comment.