[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

URI.parse and whitespace characters

Marcelo Barbudas

4/13/2009 10:54:00 AM

Hi,

I have to parse a lot of bad links like:
http://www.somethi... 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?


--
M.

4 Answers

Dylan Evans

4/13/2009 11:02:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

That's not necessarily a bad url, you just need to encode it properly, i
believe %20 is the code for a space.
Google gives me this summary;
http://www.blooberry.com/indexdot/html/topics/urlen...


On Mon, Apr 13, 2009 at 8:54 PM, Marcelo Barbudas <nostef@gmail.com> wrote:

> Hi,
>
> I have to parse a lot of bad links like:
> http://www.somethi... 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?
>
>
> --
> M.
>
>


--
The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

Andrew Timberlake

4/13/2009 11:06:00 AM

0

On Mon, Apr 13, 2009 at 12:54 PM, Marcelo Barbudas <nostef@gmail.com> wrote:
> Hi,
>
> I have to parse a lot of bad links like:
> http://www.somethi... 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?
>
>
> --
> M.
>
>

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

Andrew Timberlake
http://ramblingso...
http://www.linkedin.com/in/andrew...

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

Marcelo Barbudas

4/13/2009 11:34:00 AM

0

Thanks for both the answers.

CGI.escape is my friend:)

--
M.

Sean O'Halpin

4/13/2009 10:24:00 PM

0

On Mon, Apr 13, 2009 at 12:34 PM, Marcelo Barbudas <nostef@gmail.com> wrote:
> Thanks for both the answers.
>
> CGI.escape is my friend:)
>
> --
> M.
>
>

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