URL encoder & parser

Percent-encode, decode, and break a URL into its parts and query pairs.

URL parts

Protocol
https:
Host
tools.seanfunk.com
Path
/search
Fragment
#results

Query parameters

KeyValue
q3 tbsp to tsp
langen

How it works

Percent-encoding replaces unsafe bytes with % followed by two hex digits. A space becomes %20, and a character outside ASCII becomes several escapes — one per UTF-8 byte, which is why é is %C3%A9.

The plus-sign problem

In application/x-www-form-urlencoded — HTML form submissions — a space is encoded as +, not %20. Elsewhere in a URL, + is a literal plus. This is why a search for “C++” sometimes arrives as “C ”. The decoder above treats + as a space, matching form behaviour.

Reserved versus unreserved

RFC 3986 leaves A–Z a–z 0–9 - . _ ~ unescaped everywhere. Everything else is either reserved with structural meaning or must be escaped. Encoding an already-encoded string double-escapes it: %20 becomes %2520, a bug that is easy to create and hard to spot.