Skip to content

URI parser cannot parse URNs #379

Open
@Reisen

Description

@Reisen

It seems the URI parser stumbles with URNs. A simple test to reproduce:

fn main() {
    use http::uri::Uri;
    let uri = "urn:isbn:1238492".parse::<Uri>();
    println!("{:?}", uri);
}

Produces the output:

$ ./testcase
Err(InvalidUri(InvalidAuthority))

The authority is only present when the scheme is followed by //, otherwise the parser should be parsing everything after the first : as the path. Python gets this right, and Go parses this as Opaque (instead of Host, but still successfully parses):

Python:

>>> urlparse('urn:isbn:0451450523')
ParseResult(scheme='urn', netloc='', path='isbn:0451450523', params='', query='', fragment='')

Go:

>>> url, _ := url.Parse("urn:isbn:0451450523")
>>> fmt.Println("Host (Opaque):", url.Opaque)
Host (Opaque): isbn:0451450523

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