URL parser for Rust
docs.rs/url/

Simon Sapin c36aac6abd Upgrade to Rust 25951b2 2014-05-30 12 년 전
.gitignore 0339bc2d9a Start with an empty crate. 13 년 전
LICENSE-APACHE 0339bc2d9a Start with an empty crate. 13 년 전
LICENSE-MIT 0339bc2d9a Start with an empty crate. 13 년 전
Makefile.in 9835ae3bc3 Test and fix punycode decoding. 12 년 전
README.md affce4116d More doc tweaks. 12 년 전
configure 0339bc2d9a Start with an empty crate. 13 년 전
form_urlencoded.rs c36aac6abd Upgrade to Rust 25951b2 2014-05-30 12 년 전
parser.rs c36aac6abd Upgrade to Rust 25951b2 2014-05-30 12 년 전
punycode.rs c36aac6abd Upgrade to Rust 25951b2 2014-05-30 12 년 전
punycode_tests.json 9835ae3bc3 Test and fix punycode decoding. 12 년 전
tests.rs c36aac6abd Upgrade to Rust 25951b2 2014-05-30 12 년 전
url.rs c36aac6abd Upgrade to Rust 25951b2 2014-05-30 12 년 전
urltestdata.txt af590112c2 Fix tests. 12 년 전

README.md

rust-url

Rust implementation of the URL Standard.

See Rust bug #10707.

This depends on rust-encoding.

API

pub struct URL {
    scheme: ~str,
    scheme_data: SchemeData,
    query: Option<~str>,  // See form_urlencoded::parse_str() to get name/value pairs.
    fragment: Option<~str>,
}

pub enum SchemeData {
    RelativeSchemeData(SchemeRelativeURL),
    OtherSchemeData(~str),  // data: URLs, mailto: URLs, etc.
}

pub struct SchemeRelativeURL {
    userinfo: Option<UserInfo>,
    host: Host,
    port: ~str,
    path: ~[~str],
}

pub struct UserInfo {
    username: ~str,
    password: Option<~str>,
}

pub enum Host {
    Domain(~[~str]),  // Can only be empty in the file scheme
    IPv6(IPv6Address)
}

pub struct IPv6Address {
    pieces: [u16, ..8]
}


pub type ParseResult<T> = Result<T, &'static str>;

impl URL {
    // base_url is used to resolve relative URLs.
    // Relative URLs without a base return an error.
    pub fn parse(input: &str, base_url: Option<&URL>) -> ParseResult<URL>
    pub fn serialize(&self) -> ~str
    pub fn serialize_no_fragment(&self) -> ~str
}

impl Host {
    pub fn parse(input: &str) -> ParseResult<Host>
    pub fn serialize(&self) -> ~str
}

impl IPv6Address {
    pub fn parse(input: &str) -> ParseResult<IPv6Address>
    pub fn serialize(&self) -> ~str
}


/// application/x-www-form-urlencoded
/// Converts between a query string and name/value pairs.
pub mod form_urlencoded {
    pub fn parse_str(input: &str) -> ~[(~str, ~str)]
    pub fn parse_bytes(input: &[u8], encoding_override: Option<encoding::EncodingRef>,
                       use_charset: bool, isindex: bool) -> Option<~[(~str, ~str)]>
    pub fn serialize(pairs: ~[(~str, ~str)],
                     encoding_override: Option<encoding::EncodingRef>) -> ~str
}

To do

Not necessarily in the given order:

  • Add proper documentation
  • Add data: URL parsing.
  • Port rust-http and Servo.
  • Add IDNA support. Non-ASCII domains are a parse error for now. Punycode is done, Nameprep is the other big part.
  • Add lots of tests. Contribute them to web-platform-tests.
  • Report know/suspected spec bugs and test suite bugs.
  • Refactor to reduce code duplication.
  • Consider switching the spec from a state machine to functional style, like this code.