Percent-encoding (source code)

= Percent-encoding

<Percent-encoding> represents a <byte> using a percent sign followed by two <hexadecimal> digits. For example, byte value 32 is written `%20`. Non-<ASCII> text is first encoded as <bytes>: in <UTF-8>, `é` becomes the two bytes hexadecimal `C3 A9`, represented as `%C3%A9`.<Uniform Resource Identifier (URI): Generic Syntax>[Section2.1: percent-encoded octets]{ref}

A useful example distinguishes data from delimiters. The path in `https://example.org/a/b` has two segments; the path in `https://example.org/a%2Fb` retains the encoded slash within one segment in the parsed <URL record>. A server may apply additional decoding, but the two spellings must not be assumed interchangeable at every processing stage.

<Percent-encoding> is neither encryption nor a universal instruction to decode repeatedly. The string `%252F` decodes once to the text `%2F`; a second decoding changes it again. Likewise, the plus sign is not universally a space: that convention belongs to form-style <query string> processing, including <URLSearchParams>, rather than all URL components.<URL Standard by WHATWG>[Section1.3; Section5: form-urlencoded processing]{ref}