url: Fix edge-case when protocol is non-lowercase
When using url.parse(), path and pathname usually return '/' when there is no path available. However when you have a protocol that contains non-lowercase letters and the input string does not have a trailing slash, both path and pathname will be undefined.
This commit is contained in:
parent
04e0324f6a
commit
48a4600c56
@ -318,7 +318,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
this.query = {};
|
this.query = {};
|
||||||
}
|
}
|
||||||
if (rest) this.pathname = rest;
|
if (rest) this.pathname = rest;
|
||||||
if (slashedProtocol[proto] &&
|
if (slashedProtocol[lowerProto] &&
|
||||||
this.hostname && !this.pathname) {
|
this.hostname && !this.pathname) {
|
||||||
this.pathname = '/';
|
this.pathname = '/';
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,16 @@ var parseTests = {
|
|||||||
'path': '/'
|
'path': '/'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'HTTP://www.example.com' : {
|
||||||
|
'href': 'http://www.example.com/',
|
||||||
|
'protocol': 'http:',
|
||||||
|
'slashes': true,
|
||||||
|
'host': 'www.example.com',
|
||||||
|
'hostname': 'www.example.com',
|
||||||
|
'pathname': '/',
|
||||||
|
'path': '/'
|
||||||
|
},
|
||||||
|
|
||||||
'http://www.ExAmPlE.com/' : {
|
'http://www.ExAmPlE.com/' : {
|
||||||
'href': 'http://www.example.com/',
|
'href': 'http://www.example.com/',
|
||||||
'protocol': 'http:',
|
'protocol': 'http:',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user