url.parse bug?

40 views
Skip to first unread message

Mark Volkmann

unread,
Oct 20, 2014, 11:39:32 AM10/20/14
to nod...@googlegroups.com
This result seems to contradict the documentation for the url.parse method slashesDenoteHost parameter.

var url = require('url');
var urlString = 'http://foo/bar/baz';

var urlObj = url.parse(urlString, true, true);
console.log('host =', urlObj.host); // foo
console.log('pathname =', urlObj.pathname); // bar/baz, but expect /bar/baz

var urlObj = url.parse(urlString, true, false);
console.log('host =', urlObj.host); // foo, but don't know what should be expected
console.log('pathname =', urlObj.pathname); // bar/baz, but expected //foo/bar/baz

--
R. Mark Volkmann
Object Computing, Inc.

Jimb Esser

unread,
Oct 20, 2014, 6:52:29 PM10/20/14
to nod...@googlegroups.com
If you're parsing a url string which includes a protocol, I think the third argument shouldn't do anything at all, which is what you're seeing, it only affects urls like "//foo/bar/baz" with no protocol, which would usually, in the web world, mean a relative path on the current host, but in some contexts (such as SMB paths, but I'm sure there's others) means "bar/baz" on server "foo", which is what that third parameter is for.

Also, when running your code, I'm seeing a preceding slash on .pathname in all instances, which matches expectations, what version of Node are you running?
Reply all
Reply to author
Forward
0 new messages