Skip to content

v2.0.0

Compare
Choose a tag to compare
@slevithan slevithan released this 22 May 22:38
· 48 commits to main since this release

This is a major, breaking change that comes 17 years after v1.2.2. It updates parseUri’s API, adds new features, includes bug/security fixes, adds tests, uses modern JavaScript, becomes a truly universal URI parser, and remains tiny.

Breaking Changes

  • Renamed many URI part properties to better mach the built-in URL object and other URI libraries: sourcehref, userInfouserinfo, hosthostname, relativeresource, pathpathname, filefilename, anchorfragment, queryKeyqueryParams.
  • Updated queryParams to be returned as a URLSearchParams object, with support for multiple query keys with the same name.
  • Now uses what used to be called strict parsing mode by default.
  • The parsing mode is now specified via an argument (options: 'default', 'friendly').
  • Friendly parsing mode (formerly called loose mode) is now consistent with default mode in considering '/entry' to include {filename: 'entry'} rather than treating 'entry' as part of directory.
  • Removed parseUri.options properties, including the ability to rename URI keys or provide a non-standard query parser.

New Features

  • Added six new URI parts to result objects: origin, host, subdomain, domain, tld, suffix.
    • tld includes extensible support for second-level domains that should be treated as part of the top-level domain (ex: co.uk).
  • Added support for IPv6 addresses.

Improvements

  • Improved handling for web protocol (http, https, ws, wss, ftp) and protocol-relative URLs, for parsing accuracy and security.
  • Improved handling for URNs.
  • Added an extensive test suite.
  • Added a demo page for testing and comparison with v1, the built-in URL constructor, and other libraries.

Bug Fixes

  • Fixed an issue where @ in the resource led to incorrect parsing.
  • Fixed an ReDoS vulnerability with extremely long URIs that use @ in the resource.
  • Fixed numerous additional edge cases with atypical/invalid URIs.