From bbe8877c3760fed7e44817f00c3f0a6d9a5e4b56 Mon Sep 17 00:00:00 2001 From: hotoo Date: Sat, 29 Mar 2014 15:05:53 +0800 Subject: [PATCH] #3, fixed query to search --- src/url.js | 14 +++++++------- tests/url-spec.js | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/url.js b/src/url.js index c32ade6..23b6139 100644 --- a/src/url.js +++ b/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+))?))(\/[^\?#]+)?(\?[^#]+)?(#.*)?/; @@ -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] || ""; }; @@ -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; }; @@ -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; }; @@ -136,7 +136,7 @@ define(function(require, exports, module) { }else{ this._query[name] = value; } - this.query = makeQueryString(this._query); + this.search = makeQueryString(this._query); return this; }; @@ -144,7 +144,7 @@ define(function(require, exports, module) { // @return {Url} this. Url.prototype.clearParams = function(){ this._query = {}; - this.query = makeQueryString(this._query); + this.search = makeQueryString(this._query); return this; }; diff --git a/tests/url-spec.js b/tests/url-spec.js index cbf1017..26c5045 100644 --- a/tests/url-spec.js +++ b/tests/url-spec.js @@ -12,7 +12,7 @@ define(function(require) { hostname: "www.example.com", port: "80", path: "/", - query: "", + search: "", hash: "" }], ["http://www.example.com/", { @@ -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", { @@ -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", { @@ -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", { @@ -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", { @@ -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" }], ]; @@ -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); });