Code Monkey home page Code Monkey logo

Comments (6)

nox avatar nox commented on July 24, 2024

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

from rust-url.

nox avatar nox commented on July 24, 2024

Oh wait, no, I stand corrected:

      reg-name    = *( unreserved / pct-encoded / sub-delims )

from rust-url.

frewsxcv avatar frewsxcv commented on July 24, 2024

FWIW

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

is true for both Firefox and Chrome

from rust-url.

SimonSapin avatar SimonSapin commented on July 24, 2024

@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.

from rust-url.

frewsxcv avatar frewsxcv commented on July 24, 2024

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 👍

from rust-url.

SimonSapin avatar SimonSapin commented on July 24, 2024

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.

from rust-url.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.