URL encoding: preserve a value without breaking the link

A link can work until you add a name containing &, + or a space. The name is not necessarily invalid; some characters also have structural jobs inside URLs.

A value is not the entire URL

Encode a search parameter’s value so that & does not start another parameter and # does not start a fragment. Encoding a complete address instead needs to preserve its structural separators.

Choose according to the input you have: a whole address, a component or a form value. Correct output for one context is not automatically suitable for another.

References: WHATWG URL Standard — Percent encoding and form encoding

A plus sign has context-dependent meaning

Form encoding uses + for a space and %2B for a literal plus sign. Component encoding normally uses %20 for a space and does not automatically treat + as one.

Do not replace every plus sign before establishing the source format. Keep the original user value conceptually separate from its transport representation.

References: WHATWG URL Standard — Percent encoding and form encoding

Decoding is a defined step, not a repair loop

Decoding twice can change meaning. Establish how many encoding layers the producing system intended rather than repeating the operation until the text looks familiar.

This tool changes textual representation; it does not visit or verify the destination. A readable decoded address is not proof of trustworthiness, and encoding sensitive information does not hide it.

Example: a value with a plus sign, spaces and an ampersand

A+B & C becomes A%2BB%20%26%20C as an encoded component. Form encoding gives A%2BB+%26+C. Each returns to the original value when decoded using its matching convention.

By contrast, %252F decodes once to %2F and twice to /. That difference can alter a path or value, so repeated decoding is not automatically safe cleanup.

References