Skip to content

Commit

Permalink
Close nodejs#562 Close nodejs#1078 Parse file:// urls properly
Browse files Browse the repository at this point in the history
The file:// protocol *always* has a hostname; it's frequently
abbreviated as an empty string, which represents 'localhost'
implicitly.

According to RFC 1738 (http://tools.ietf.org/html/rfc1738):

A file URL takes the form:

   file://<host>/<path>

where <host> is the fully qualified domain name of the system on
which the <path> is accessible...

As a special case, <host> can be the string "localhost" or the empty
string; this is interpreted as 'the machine from which the URL is
being interpreted'.
  • Loading branch information
ryanpetrello authored and isaacs committed May 20, 2011
1 parent 70dd6d4 commit 4e66ff5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ var protocolPattern = /^([a-z0-9]+:)/i,
// protocols that never have a hostname.
hostlessProtocol = {
'javascript': true,
'javascript:': true,
'file': true,
'file:': true
'javascript:': true
},
// protocols that always have a path component.
pathedProtocol = {
Expand Down
30 changes: 28 additions & 2 deletions test/simple/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,38 @@ var parseTests = {
'file:///etc/passwd' : {
'href': 'file:///etc/passwd',
'protocol': 'file:',
'pathname': '///etc/passwd'
'pathname': '/etc/passwd',
'hostname': ''
},
'file://localhost/etc/passwd' : {
'href': 'file://localhost/etc/passwd',
'protocol': 'file:',
'pathname': '/etc/passwd',
'hostname': 'localhost'
},
'file://foo/etc/passwd' : {
'href': 'file://foo/etc/passwd',
'protocol': 'file:',
'pathname': '/etc/passwd',
'hostname': 'foo'
},
'file:///etc/node/' : {
'href': 'file:///etc/node/',
'protocol': 'file:',
'pathname': '///etc/node/'
'pathname': '/etc/node/',
'hostname': ''
},
'file://localhost/etc/node/' : {
'href': 'file://localhost/etc/node/',
'protocol': 'file:',
'pathname': '/etc/node/',
'hostname': 'localhost'
},
'file://foo/etc/node/' : {
'href': 'file://foo/etc/node/',
'protocol': 'file:',
'pathname': '/etc/node/',
'hostname': 'foo'
},
'http:/baz/../foo/bar' : {
'href': 'http:/baz/../foo/bar',
Expand Down

0 comments on commit 4e66ff5

Please sign in to comment.