scrrr
scrrr

Reputation: 5340

Prevent escaping brackets in URLs

Our image server allows us to pass url parameters that trigger certain image manipulation operations. For instance the url https://www.example.com/i/example/10570250?layer0=[w=600&h=1000&bg=rgba(228,228,228,125)&cm=multi] scales the image and applies a blending mode.

The problem is that as soon as feed that string into an URL object, for example with URL(string: "https://www.example.com/i/example/10570250?layer0=[w=600&h=1000&bg=rgba(228,228,228,125)&cm=multi]") the brackets get escaped and the image server stops applying the operations.

The url becomes: https://www.example.com/i/example/10570250?layer0=%5Bw=600&h=1000&bg=rgba(228,228,228,125)&cm=multi%5D

Can I prevent URL from escaping the brackets? Or ist there some other way of escaping the url, before feeding it to URL(string:), that the image server might accept?

Upvotes: 0

Views: 269

Answers (1)

Rashwan L
Rashwan L

Reputation: 38833

You´re not allowed to include [ ] in your URL. Consider changing your API call to make this work for you.

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. In
anticipation of future, as-yet-undefined IP literal address formats,
an implementation may use an optional version flag to indicate such a format explicitly rather than rely on heuristic determination.

Reference.

Upvotes: 2

Related Questions