Skip to content

ABNF: uri reference

Ryan Parman edited this page Jun 8, 2024 · 3 revisions

Overview

A URI-reference is either a URI or a relative reference. If the URI-reference's prefix does not match the syntax of a scheme followed by its colon separator, then the URI-reference is a relative reference.

A URI-reference is typically parsed first into the five URI components, in order to determine what components are present and whether the reference is relative.

  • scheme
  • host + port (authority)
  • path
  • query
  • fragment

Then, each component is parsed for its subparts and their validation. The ABNF of URI-reference, along with the "first-match-wins" disambiguation rule, is sufficient to define a validating parser for the generic syntax. Readers familiar with regular expressions should see Appendix B for an example of a non-validating URI-reference parser that will take any given string and extract the URI components.

ABNF (RFC 3986 § 4.1)

URI-reference = URI / relative-ref

relative-ref  = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
              / path-absolute
              / path-noscheme
              / path-empty

Instead of following RFC 3986, we use a URL parser which aligns with the WHATWG URL Living Standard (2023-05-24 snapshot), which is itself meant to supersede older URL specifications.

Clone this wiki locally