Forum: Ruby Square brackets in URI

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Niklas Hofer (Guest)
on 2007-06-30 03:18
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello

 I was trying to handle some user entered URL/Is and came across the
following problem: How do I handle URIs with brackets in the path part?

require 'uri'
u = "http://my.wonder.fu/ll url [with brackets]"
ue = URI.escape u
puts "Escaped. The brackets stay the same:"
puts ue

begin
  up = URI.parse u
rescue URI::InvalidURIError
  puts "Parsing the unescaped string breaks."
end

begin
  uep = URI.parse ue
rescue URI::InvalidURIError
  puts "Even parsing the escaped string breaks."
end

ruby 1.8.5 (2006-08-25) [i486-linux]
 (1.8.5-4ubuntu2)
Linux wigowyr 2.6.20-16-generic #1 SMP Tue May 29 17:59:55 CEST 2007
i686 GNU/Linux

I saw the URI::REGEXP::PATTERN::UNSAFE already includes ...::RESERVED
characters, but the way it is used confused me.. maybe it's to late for
me tonight.

Any ideas?

Niklas
- --

 _ o                         o    |    o       >    =            o)
  /\    - =   <             (|/   |   \|)               \       (|
 | \                        /)    |    (\          \  _ /       / \

The game of life is a game of boomerangs.  Our thoughts, deeds and words
return to us sooner or later with astounding accuracy.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGhZMMy/Xs5T5Y7qwRAjPPAJ9kYQf5+SyZ8MuX1D10EeN91LxQ+QCgwIwJ
p8es68RUeE5D+YbP7N/hxU8=
=nZ2q
-----END PGP SIGNATURE-----
This topic is locked and can not be replied to.