Sorry, that replace statement collapses multiple plus signs into a single 
space, but that's probably never what you want, my mistake! Should be this:

        
decodeURIComponent(url.parse("http://host/path/some+thing%20with%20spaces+in+it/bar";,
 true).path.replace(/\+/g, ' '))

Alternatively, there's this little trick, but I prefer the above personally!

        
decodeURIComponent(url.parse("http://host/path/some+thing%20with%20spaces+in+it/bar";,
 true).path.split('+').join(' '))

-Matt


On Apr 24, 2012, at 4:51 PM, Matt Patenaude wrote:

> If Node automatically performed a URL decode on the pathname, you lose data — 
> e.g., if your application depended on knowing whether someone encoded a space 
> as a "+" or %20 (it seems silly, but let's say you can contrive an example 
> where that matters), you'd have no way to tell from that information. URL 
> parsing and decoding are conceptually separate steps, and the implementation 
> in Node reflects that.
> 
> You should be able to get a correctly-decoded URL using something like:
> 
>       
> decodeURIComponent(url.parse("http://host/path/some+thing%20with%20spaces+in+it/bar";,
>  true).path.replace(/\++/g, ' '))
> 
> Just make sure you always resolve the +'s first, because if someone 
> percent-encodes a literal + sign, that would then be translated into a space 
> if done in the wrong order.
> 
> Hope that helps!
> 
> -Matt
> 
> 
> On Apr 24, 2012, at 4:25 PM, Matt wrote:
> 
>> > url.parse("http://host/path/some+thing%20with%20spaces+in+it/bar";, true);
>> { protocol: 'http:',
>>   slashes: true,
>>   host: 'host',
>>   hostname: 'host',
>>   href: 'http://host/path/some+thing%20with%20spaces+in+it/bar',
>>   search: '',
>>   query: {},
>>   pathname: '/path/some+thing%20with%20spaces+in+it/bar',
>>   path: '/path/some+thing%20with%20spaces+in+it/bar' }
>> 
>> I kind of hoped it would set the path to '/path/some thing with spaces in 
>> it/bar' which would be appropriate for passing to the filesystem. How come 
>> it doesn't decode the path?
>> 
>> -- 
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines: 
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to nodejs@googlegroups.com
>> To unsubscribe from this group, send email to
>> nodejs+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
> 
> 
> -- 
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to