1

I have read this question: Is it ok to have brackets in URL? and the related RFC 3986.

Answers to this question say that [ and ] are classified as gen-delims by the RFC and should therefore be encoded, but do not explain how failing to do so would be problematic.

So, I fail to understand what can be the problem with a URL such as:

http://example.com/?foo[bar]=baz

It is obvious why & should be encoded for example, as it is used as a separator between query parameters.

But what is the use of [ and ] in a URL that would make their intent confusing if they were not URL-encoded?

Community
  • 1
  • 1
BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0

From RFC 3986 section 3.2.2:

A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]").

For example, the IPv4 address for you local machine is 127.0.0.1, so you can access it with the url

http://127.0.0.1/

The IPv6 equivalent is ::1, so the url would be

http://[::1]/
mcrumley
  • 5,682
  • 3
  • 25
  • 33
  • I've seen this line, but am not sure to understand it. Could you please give an example? – BenMorel Jan 03 '14 at 18:56
  • That answers my question then, thanks. It's unfortunate that the RFC forces square brackets to be encoded in URL parameters, even though they seemingly can only be used in the host part. – BenMorel Jan 03 '14 at 19:04