Skip to content

An empty authority with an unknown spec is not parsed properly #443

Description

@llimllib

This issue comes from Bryan Nebold's post about DID URLs, and I think trurl is parsing empty authorities incorrectly.

The atmosphere URI at://did:plc:whatever/more/path/here is invalid, because did:plc:whatever is an invalid authority; it does not conform to the host:port syntax from RFC 3986. trurl is well within its rights to refuse to parse it:

$ trurl --json 'at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g' 
trurl note: Port number was not a decimal number between 0 and 65535 [at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g]
[]

However, the URI at:///did:plc:whatever/more/path/here has an extra slash, which should indicate an empty authority, and did:plc:whatever/more/path/here ought to be the path. Firefox parses it like this:

Image

However, trurl treats it exactly the same, tries to parse a port out of what ought to be the first segment of the path, and exits with an error:

$ trurl --json 'at:///did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g'
trurl note: Port number was not a decimal number between 0 and 65535 [at:///did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g]
[]

If we simplify the URL to see what's going on, trurl will tell us it has parsed the path's first segment as a host:

$ trurl --json 'at:///foo'
[
  {
    "url": "at://foo/",
    "parts": {
      "scheme": "at",
      "host": "foo",
      "path": "/"
    }
  }
]

trurl appears to be silently removing a semantically important front-slash.

For whatever it's worth, curl seems to behave identically, parsing foo as the host:

$ curl -w '%{url.scheme} %{url.host} %{url.port} %{url.path}\n' 'at:///foo'
curl: (1) Protocol "at" not supported
at foo  /

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions