PRACTICAL GUIDE

Encode a Query Value Without Breaking URL Separators

A query value can contain spaces, ampersands or other characters with special URL meanings.

Encode a component rather than an assembled URL

A query value can contain spaces, ampersands or other characters with special URL meanings. Encode that value before placing it in a URL. Encoding the entire assembled address also escapes its structural separators.

Treat spaces and plus signs separately

Form submissions often use plus for spaces, while a literal plus is escaped as %2B. A normal URL-component decoder does not automatically treat every plus as a space. Select the convention used by the producer.

Avoid unintended double encoding

The percent sign is itself escaped during encoding. Passing an already encoded value through the encoder again can turn %20 into %2520. Decode or encode only at the layer required by your application.

Do not confuse encoding with security

An encoded address can still lead to an unwanted destination. Decoding helps you inspect representation, but it does not authenticate a website or make untrusted content safe to execute.

Put it into practice