Breaking
- Require Node.js 22 6c95de2
- Throw a
TypeErrorwhen thedefaultProtocoloption is not a valid scheme, such as'https://'a8c34ae - The query is now always re-serialized, even with
sortQueryParameters: false65f62ef- Previously, disabling sorting kept the query exactly as written. Now it is written the way
URLSearchParamswrites it, so%20becomes+and an escape that is not valid UTF-8, like%E9, becomes%EF%BF%BD.
- Previously, disabling sorting kept the query exactly as written. Now it is written the way
- The
removeDirectoryIndexoption now runs aftertransformPath, so the function also receives the index file 65f62ef - Many edge cases are now normalized differently (see below). If you store normalized URLs, you may want to normalize them again.
Improvements
- The
defaultProtocoloption now accepts any protocol, not justhttpandhttpsb2e4135 - Strip all whitespace from the ends of a URL, including a non-breaking space and a byte order mark left over from copying 13f62a4
- Keep repeated query keys in their original order when sorting 5a3e67a
- Normalizing an already normalized URL now always gives the same URL
- Document the normalizations that happen regardless of the options bb685bc
Fixes
- Fix normalization of the protocol, host, port, path, query, fragment, and data URLs 65f62ef
http:/example.comno longer becomeshttp://http/example.com%252Fin a path no longer becomes%2F, which is a different URL- A trailing
/in the query is no longer removed normalizeProtocol: falsenow keeps a protocol-relative URL, even withdefaultProtocol: 'https'- A data URL without a comma no longer throws
- Fix several data URL cases where the normalized URL was decoded differently by browsers 5d8ff58 cf2aed8 bd39d02