# Are square brackets not allowed in a URI?

**URL:** <https://www.ruby-forum.com/t/are-square-brackets-not-allowed-in-a-uri/145805>\
**Category:** Ruby\
**Created:** [August 14, 2008, 6:15am UTC](https://www.ruby-forum.com/t/are-square-brackets-not-allowed-in-a-uri/145805 "2008-08-14T06:15:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [August 14, 2008, 6:15am UTC](https://www.ruby-forum.com/t/are-square-brackets-not-allowed-in-a-uri/145805/1 "2008-08-14T06:15:52Z")

</div>

I could swear that this URL works:

[http://www.teamliquid.net/tlpd/players/189\_YellOw[ArnC]](http://www.teamliquid.net/tlpd/players/189_YellOw%5BArnC%5D)

```
...but parsing this with URI throws an exception claiming that this 

```

is  
invalid.  
I don’t know exactly what URI’s are but Mechanize is using it to  
parse  
URLs and this appears to be a valid URL so it looks like either  
Mechanize’s  
bug is in using Ruby’s URI module or the URI module in not accepting  
valid  
URLs. Either that or there’s something I’m totally not understanding  
(like  
my browser lying to me or something). Can someone tell me what’s going  
on?  
Thank you!

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [August 14, 2008, 6:34am UTC](https://www.ruby-forum.com/t/are-square-brackets-not-allowed-in-a-uri/145805/2 "2008-08-14T06:34:00Z")

</div>

On Thu, Aug 14, 2008 at 1:12 PM, Just Another Victim of the Ambient  
Morality [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> bug is in using Ruby’s URI module or the URI module in not accepting valid  
> URLs. Either that or there’s something I’m totally not understanding (like  
> my browser lying to me or something). Can someone tell me what’s going on?  
> Thank you!

Your browser is, in fact, lying to you, the URL it opens is :  
[http://www.teamliquid.net/tlpd/players/189\_YellOw[ArnC]](http://www.teamliquid.net/tlpd/players/189_YellOw%5BArnC%5D)

Browsers always (un)escape URLs for readability, take a look for  
example at the way markdown escapes email addresses:  
[http://daringfireball.net/projects/markdown/syntax#autolink](http://daringfireball.net/projects/markdown/syntax#autolink)

While it’s unfortunate for us coders, not properly escaped hrefs in  
links are a very common thing on the web, fortunately there are not  
that many URIs that use special characters, and sometimes people  
actually do escape them before slating them into HTML, but not always.

There’s no simple workaround i can think of, short of patching uri.rb

^ manveru

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [August 14, 2008, 6:36am UTC](https://www.ruby-forum.com/t/are-square-brackets-not-allowed-in-a-uri/145805/3 "2008-08-14T06:36:56Z")

</div>

On Aug 13, 2008, at 10:12 PM, Just Another Victim of the Ambient  
Morality wrote:

> parse

[http://www.faqs.org/rfcs/rfc2396.html](http://www.faqs.org/rfcs/rfc2396.html)

"

Other characters are excluded because gateways and other transport  
agents are known to sometimes modify such characters, or they are  
used as delimiters.

```
unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"

Data corresponding to excluded characters must be escaped in order

```

to  
be properly represented within a URI.

"

a @ [http://codeforpeople.com/](http://codeforpeople.com/)
