A query parameter value
Input
search terms & more?Output
search%20terms%20%26%20more%3FThe ampersand and question mark are encoded, so they cannot be mistaken for URL structure.
Further reading
URLs may contain only a restricted set of ASCII characters, and several of those carry structural meaning: ? starts a query, & separates parameters, / separates path segments, and # begins a fragment. Percent-encoding replaces anything unsafe with a % followed by its hexadecimal byte value.
The choice that matters is scope. Encoding a value that goes inside a URL is a different operation from encoding a URL as a whole, and using the wrong one is the most common cause of broken links and lost query parameters.
Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.
Input
search terms & more?Output
search%20terms%20%26%20more%3FThe ampersand and question mark are encoded, so they cannot be mistaken for URL structure.
Input
caféOutput
caf%C3%A9The é is two UTF-8 bytes, so it produces two percent-escapes.
The details that decide whether a conversion is correct, and where information can be lost without any error being raised.