From 48a4600c5669bb2b624bf004bbbb88a2d97ff6f8 Mon Sep 17 00:00:00 2001 From: Shuan Wang Date: Wed, 17 Jul 2013 13:10:09 -0700 Subject: [PATCH] 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. --- lib/url.js | 2 +- test/simple/test-url.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/url.js b/lib/url.js index bacf201dd6..09e9cceb42 100644 --- a/lib/url.js +++ b/lib/url.js @@ -318,7 +318,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { this.query = {}; } if (rest) this.pathname = rest; - if (slashedProtocol[proto] && + if (slashedProtocol[lowerProto] && this.hostname && !this.pathname) { this.pathname = '/'; } diff --git a/test/simple/test-url.js b/test/simple/test-url.js index d27abbab8a..57d0a6d5a6 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -44,6 +44,16 @@ var parseTests = { '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/' : { 'href': 'http://www.example.com/', 'protocol': 'http:',