URI.parse and whitespace characters

M

Marcelo Barbudas

Hi,

I have to parse a lot of bad links like:
http://www.something.com/bad link.jpg
(spaces in them)

URI.parse fails parsing them and considers them as faulty links.

However in my case I need it to work. Is there a workaround for this?
 
A

Andrew Timberlake

Hi,

I have to parse a lot of bad links like:
http://www.something.com/bad link.jpg
(spaces in them)

URI.parse fails parsing them and considers them as faulty links.

However in my case I need it to work. Is there a workaround for this?

uri = "http://www.something.com/bad link.jpg"
URI.parse(uri.gsub(/ /, '+')) #<- replaces all spaces with '+'

Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
 
S

Sean O'Halpin

Thanks for both the answers.

CGI.escape is my friend:)

Just a small point - URI escaping and CGI escaping are similar but not
the same. To get URI escaping, require 'uri' and use URI.escape
instead of CGI.escape.

Regards,
Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,947
Members
47,498
Latest member
yelene6679

Latest Threads

Top