how can multiple trailing slashes can be removed from an url in Ruby

Posted by splintercell on Stack Overflow See other posts from Stack Overflow or by splintercell
Published on 2010-05-04T13:05:58Z Indexed on 2010/05/04 13:08 UTC
Read the original article Hit count: 251

Filed under:
|
|

Hello,

What i'm trying to achieve here is lets say we have two example urls:

url1 "http://emy.dod.com/kaskaa/dkaiad/amaa//////////" & url2 = "http://www.example.com/".

How can I extract the striped down urls?

url1 : "http://emy.dod.com/kaskaa/dkaiad/amaa" & url2 to "http://http://www.example.com"?

URI.parse in ruby sanitizes certain type of malformed url but is ineffective in this case.

If we use regex then /^(.*)\/$/ removes a single slash (/) from url1 & is ineffective for url2.

Is anybody aware of how to handle this type of url parsing?

The point here is I dont want my system to have "http://www.example.com/" & "http://www.example.com" being treated as two different urls.

And same goes for "http://emy.dod.com/kaskaa/dkaiad/amaa////" & "http://emy.dod.com/kaskaa/dkaiad/amaa/"

cheers,

-dg

© Stack Overflow or respective owner

Related posts about ruby

Related posts about url-parsing