Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are square brackets permitted in URLs?

Are square brackets in URLs allowed?

I noticed that Apache commons HttpClient (3.0.1) throws an IOException, wget and Firefox however accept square brackets.

URL example:

http://example.com/path/to/file[3].html 

My HTTP client encounters such URLs but I'm not sure whether to patch the code or to throw an exception (as it actually should be).

like image 334
Benedikt Waldvogel Avatar asked Sep 02 '08 20:09

Benedikt Waldvogel


People also ask

Are symbols allowed in URLs?

Original answer from RFC 1738 specification: Thus, only alphanumerics, the special characters " $-_. +! *'(), ", and reserved characters used for their reserved purposes may be used unencoded within a URL.

What characters are legal in a URL?

Based on this related answer, you are looking at a list that looks like: A-Z , a-z , 0-9 , - , . , _ , ~ , : , / , ? , # , [ , ] , @ , ! , $ , & , ' , ( , ) , * , + , , , ; , % , and = . Everything else must be url-encoded.

Can you use brackets in domain name?

Braces or curly brackets { } are used when the domain or range consists of discrete numbers and not an interval of values. If the domain or range of a function is all numbers, the notation includes negative and positive infinity . If the domain is all positive numbers plus 0, the domain would be written as .

Can you use square brackets?

Use square brackets to include words within a quote that are not part of the original quote. For example, if a quoted passage is not entirely clear, words enclosed in square brackets can be added to clarify the meaning.


1 Answers

RFC 3986 states

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 "]"). This is the only place where square bracket characters are allowed in the URI syntax.

So you should not be seeing such URI's in the wild in theory, as they should arrive encoded.

like image 70
Justin Cormack Avatar answered Oct 13 '22 20:10

Justin Cormack