I'm having some trouble using curl for any URLs which contain square brackets.
For example:
$ curl 'http://example.org/?param[0]=true'
curl: (3) [globbing] bad range in column 27
How do I properly escape the square brackets so that curl will issue the request?
There is no escaping character in an URL Rewrite expression, but here is how you include curly bracket within an URL Rewrite expression. For closing } curly bracket you don't have do anything if the character is not nested in a another URL Rewrite expression; otherwise you need to use UrlDecode with %7D.
Parentheses “()” may be used as such in the query part of URL (i.e., the part after “?”). It is allowable, but not necessary, to %-encode them, as “%28” and “%29”. Brackets “[]” shall be %-encoded, as “%5B” and “%5D”, in the query part.
As mentioned previously, curly braces are unsafe characters, and are not valid in URIs (see RFC 3986). For the purposes of API documentation, and other similar uses, they should not be percent encoded, however, because they still aren't URIs - they don't identify a resource.
curl offers "globbing" as a way to specify many URLs like that easily. The globbing uses the reserved symbols [] and {} for this, symbols that normally cannot be part of a legal URL (except for numerical IPv6 addresses but curl handles them fine anyway). If the globbing gets in your way, disable it with -g, --globoff .
It turns out that curl is trying to interpret the square brackets as a globbing pattern.
Luckily there is a curl option to turn the globbing behavior off:
$ curl -g 'http://example.org/?param[0]=true'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With