Skip to content

Cannot parse usernames in path urls. #25

Closed

Description

@alexcrichton

In rust-postgres, there's a test that generates a url like so:

let mut url = Url::from_file_path(&Path::new(unix_socket_directory)).unwrap();
*url.username_mut().unwrap() = "postgres".to_string();                         
url.scheme = "postgres".to_string();                                           

When printed, the url is:

postgres://postgres@/var/run/postgresql

But when this url is parsed, it parses to a url with an empty host (a parser error).

Activity

  1. nox commented on Jun 14, 2015

    @nox
    Contributor

    You are trying to parse an URL with an authority (scheme://authority), an authority must include a non-empty host.

  2. nox commented on Jun 14, 2015

    @nox
    Contributor

    Oh wait, no, I stand corrected:

          reg-name    = *( unreserved / pct-encoded / sub-delims )
    
  3. frewsxcv commented on Aug 17, 2015

    @frewsxcv
    Contributor

    FWIW

    new URL("postgres://postgres@/var/run/postgresql").username === ""

    is true for both Firefox and Chrome

  4. SimonSapin commented on Aug 17, 2015

    @SimonSapin
    Member

    @alexcrichton Not sure why I didn’t respond to this a year ago, sorry. To use "non-standard" schemes like postgres: you probably want a custom "scheme type mapper" https://servo.github.io/rust-url/url/struct.UrlParser.html#method.scheme_type_mapper .

    @nox Where is that quote from? This crates implements http://url.spec.whatwg.org/ which sometimes diverges from the various relevant IETF RFCs.

    @frewsxcv The Rust API of this crate and its behavior is not necessarily the same as https://url.spec.whatwg.org/#api (which is designed for JavaScript and web compat) as long as it enables Servo to implement it on top.

  5. frewsxcv commented on Aug 17, 2015

    @frewsxcv
    Contributor

    The Rust API of this crate and its behavior is not necessarily the same as https://url.spec.whatwg.org/#api (which is designed for JavaScript and web compat) as long as it enables Servo to implement it on top.

    I thought about that possibility, but wasn't sure. Thanks for clarifying 👍

  6. added 2 commits that reference this issue on Apr 21, 2016
    ceb1878
    bb72f19
  7. SimonSapin commented on Apr 21, 2016

    @SimonSapin
    Member

    This passes in 1.0:

        let mut url = Url::from_file_path(filename).unwrap();
        url.set_scheme("postgres").unwrap();
        url.set_host(Some("")).unwrap();
        url.set_username("me").unwrap();
        assert_eq!(url.as_str(), "postgres://me@/run/pg.sock");

    The idea is that you can’t have a username without a host, but an empty host is not the same as no host. It’s not clear whether empty hosts make sense though, so I don’t know if it’s a good idea to rely on them. (The spec might change to forbid them and I’ll update rust-url to follow.) set_host(Some("localhost")) would be safe, though.

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