return null;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v)) {
this._port = -1;
if (this._host)
this._host = null;
return (p == null && s) ? ('/' + s) : null;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v)) {
this._pathname = this._search = null;
return;
}
return proto;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v)) {
this._protocol = null;
} else {
var proto = '' + v;
var parsesQueryStrings = this._parsesQueryStrings;
// Reset properties.
Url.call(this);
- if (v !== null && v !== '')
+ if (!isConsideredEmpty(v))
this.parse('' + v, parsesQueryStrings, false);
},
enumerable: true,
return this._auth;
},
set: function(v) {
- this._auth = v === null ? null : '' + v;
+ this._auth = isConsideredEmpty(v) ? null : '' + v;
this._href = '';
},
enumerable: true,
return this._host;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v)) {
this._port = -1;
this._hostname = this._host = null;
} else {
return this._hostname;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v)) {
this._hostname = null;
if (this._hasValidPort())
return this._hash;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v) || v === '#') {
this._hash = null;
} else {
var hash = '' + v;
return this._search;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v) || v === '?') {
this._search = this._query = null;
} else {
var search = escapeSearch('' + v);
return this._pathname;
},
set: function(v) {
- if (v === null) {
+ if (isConsideredEmpty(v)) {
this._pathname = null;
} else {
var pathname = escapePathName('' + v).replace(/\\/g, '/');
configurable: true
});
+function isConsideredEmpty(value) {
+ return value === null || value === undefined || value === '';
+}
+
// Search `char1` (integer code for a character) in `string`
// starting from `fromIndex` and ending at `string.length - 1`
// or when a stop character is found.
}, {
// Setting href to non-null non-string coerces to string
url: 'google',
- set: {href: undefined},
+ set: {href: 0},
test: {
- path: 'undefined',
- href: 'undefined'
+ path: '0',
+ href: '0'
}
}, {
// Setting port is reflected in host
url: 'http://www.google.com',
set: {search: ''},
test: {
- search: '?',
- path: '/?'
+ search: null,
+ path: '/'
}
}, {
}, {
// Empty hash is ok
- url: 'http://www.google.com',
+ url: 'http://www.google.com#hash',
set: {hash: ''},
test: {
- hash: '#'
+ hash: null,
+ href: 'http://www.google.com/'
}
}, {
url: 'http://www.google.com',
set: {pathname: ''},
test: {
- pathname: '/'
+ pathname: null,
+ href: 'http://www.google.com'
}
}, {
// Null path is ok
protocol: null
}
}, {
- // Empty protocol is invalid
+ // Empty protocol is ok
url: 'http://www.google.com/path',
set: {protocol: ''},
test: {
- protocol: 'http:'
+ protocol: null,
+ href: '//www.google.com/path'
}
}, {
// Set query to an object
url: 'http://www.google.com/path?key=value',
set: {path: '?key2=value2'},
test: {
- pathname: '/',
+ pathname: null,
search: '?key2=value2',
- href: 'http://www.google.com/?key2=value2'
+ href: 'http://www.google.com?key2=value2'
}
}, {
// path is reflected in search and pathname 3
search: null,
href: 'http://www.google.com'
}
+}, {
+ // setting hash to '' removes any hash
+ url: 'http://www.google.com/#hash',
+ set: {hash: ''},
+ test: {
+ hash: null,
+ href: 'http://www.google.com/'
+ }
+}, {
+ // setting hash to '#' removes any hash
+ url: 'http://www.google.com/#hash',
+ set: {hash: '#'},
+ test: {
+ hash: null,
+ href: 'http://www.google.com/'
+ }
+}, {
+ // setting search to '' removes any search
+ url: 'http://www.google.com/?search',
+ set: {search: ''},
+ test: {
+ search: null,
+ href: 'http://www.google.com/'
+ }
+}, {
+ // setting search to '?' removes any search
+ url: 'http://www.google.com/?search',
+ set: {search: '?'},
+ test: {
+ search: null,
+ href: 'http://www.google.com/'
+ }
}
];