# Square brackets in URI

**URL:** <https://www.ruby-forum.com/t/square-brackets-in-uri/108209>\
**Category:** Ruby\
**Created:** [June 30, 2007, 1:18am UTC](https://www.ruby-forum.com/t/square-brackets-in-uri/108209 "2007-06-30T01:18:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niklas\_Hofer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/47e85d/32.png) [@Niklas\_Hofer](https://www.ruby-forum.com/u/Niklas_Hofer)\
**Post date:** [June 30, 2007, 1:18am UTC](https://www.ruby-forum.com/t/square-brackets-in-uri/108209/1 "2007-06-30T01:18:37Z")

</div>

-----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](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-----
