Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New IntoUrl trait #177

Closed
wants to merge 40 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
918352b
Make it possible to define new encode sets in other crates.
SimonSapin Dec 4, 2015
db9de70
Define encode sets based on another set.
SimonSapin Dec 4, 2015
691aec2
Remove the HTTP_VALUE encode set. It can be defined in another crate.
SimonSapin Dec 4, 2015
d140dc8
Rewrite ALL THE THINGS!
SimonSapin Dec 9, 2015
9edff44
Remove the dependency on uuid.
SimonSapin Feb 8, 2016
576bd2a
Add URL slicing/indexing by component.
SimonSapin Feb 8, 2016
7b11445
Add stubs with partial implementation for the WebIDL API.
SimonSapin Feb 8, 2016
c617ed1
Shorter Cargo.toml syntax.
SimonSapin Feb 8, 2016
22cf104
serde_serialization -> serde
SimonSapin Feb 8, 2016
0cb3f2b
Make rustc-serialize an optional dependency.
SimonSapin Feb 8, 2016
61a8185
Rename *{Start,End} posititons to {Before,After}*
SimonSapin Feb 9, 2016
813d270
Replace from_hex() with char::to_digit(16)
SimonSapin Feb 9, 2016
0b5ffb4
Make percent-decoding an iterator.
SimonSapin Feb 9, 2016
244d999
Make percent-encoding an iterator.
SimonSapin Feb 9, 2016
7b33b33
Add percent-encoding convienience wrappers.
SimonSapin Feb 9, 2016
ca9f87d
Update tests from https://github.com/w3c/web-platform-tests/blob/mast…
SimonSapin Feb 10, 2016
7a0e467
Remove Url::has_host
SimonSapin Feb 11, 2016
9a8d394
Remove unused ParseError variants
SimonSapin Feb 12, 2016
903f1d2
Make context a field of Parser.
SimonSapin Feb 11, 2016
a9b4e71
Remove the redundant is_relative field.
SimonSapin Feb 15, 2016
ded48a2
Add Url::domain and Url::ip_address
SimonSapin Feb 15, 2016
d3dba86
Implement ToSocketAddrs
SimonSapin Feb 15, 2016
088c3ed
Remove Url::ip_address for now
SimonSapin Feb 15, 2016
641f940
Add Unicode and ASCII serializations of origins
SimonSapin Feb 16, 2016
946d950
Test WebIdl::origin
SimonSapin Feb 16, 2016
4dff876
Add a fragment setter
SimonSapin Feb 11, 2016
0ae07ed
Add a query setter.
SimonSapin Feb 12, 2016
542feb0
Make Url::parse_with usable. (EncodingOverride is private.)
SimonSapin Feb 19, 2016
dd0436a
Add Origin::is_tuple
SimonSapin Feb 19, 2016
f7e0d7c
More consistent checks for URL with authority or path-only.
SimonSapin Feb 19, 2016
fd16b74
Re-export OpaqueOrigin. It is exposed publicly through Origin::Opaque
SimonSapin Feb 19, 2016
f1bdaa6
Add a scheme setter
SimonSapin Feb 19, 2016
158145f
Add host setters.
SimonSapin Feb 19, 2016
b1b0916
More setters
SimonSapin Feb 23, 2016
47e31ef
Add a path setter
SimonSapin Feb 26, 2016
e7a4dc0
Username and passowrd setters
SimonSapin Feb 26, 2016
5b26c89
More WebIDL implementations.
SimonSapin Feb 26, 2016
bf0f670
Port setters
SimonSapin Mar 1, 2016
b89d7d7
All setters.
SimonSapin Mar 1, 2016
3f9dcd4
New IntoUrl trait
cmbrandenburg Mar 4, 2016
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Remove the redundant is_relative field.

  • Loading branch information
SimonSapin committed Mar 3, 2016
commit a9b4e71b6f22e80ea15695b3f5db2abc46dd811d
@@ -160,7 +160,6 @@ pub mod idna;
#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
pub struct Url {
serialization: String,
non_relative: bool,

// Components
scheme_end: u32, // Before ':'
@@ -169,7 +168,7 @@ pub struct Url {
host_end: u32,
host: HostInternal,
port: Option<u16>,
path_start: u32, // Before initial '/' if !non_relative
path_start: u32, // Before initial '/', if any
query_start: Option<u32>, // Before '?', unlike Position::QueryStart
fragment_start: Option<u32>, // Before '#', unlike Position::FragmentStart
}
@@ -211,7 +210,7 @@ impl Url {
&self.serialization
}

/// Return the scheme of this URL, as an ASCII string without the ':' delimiter.
/// Return the scheme of this URL, lower-cased, as an ASCII string without the ':' delimiter.
#[inline]
pub fn scheme(&self) -> &str {
self.slice(..self.scheme_end)
@@ -220,7 +219,7 @@ impl Url {
/// Return whether this URL is non-relative (typical of e.g. `data:` and `mailto:` URLs.)
#[inline]
pub fn non_relative(&self) -> bool {
self.non_relative
self.byte_at(self.path_start) != b'/'
}

/// Return the username for this URL (typically the empty string)
@@ -312,12 +311,11 @@ impl Url {
///
/// Return `None` for non-relative URLs, or an iterator of at least one string.
pub fn path_segments(&self) -> Option<str::Split<char>> {
if self.non_relative {
None
} else {
let path = self.path();
debug_assert!(path.starts_with("/"));
let path = self.path();
if path.starts_with('/') {
Some(path[1..].split('/'))
} else {
None
}
}

@@ -357,7 +355,6 @@ impl Url {
try!(path_to_file_url_segments(path.as_ref(), &mut serialization));
Ok(Url {
serialization: serialization,
non_relative: false,
scheme_end: "file".len() as u32,
username_end: path_start,
host_start: path_start,
@@ -138,7 +138,7 @@ impl<'a> Parser<'a> {
if let Some(base_url) = self.base_url {
if input.starts_with("#") {
self.fragment_only(base_url, input)
} else if base_url.non_relative {
} else if base_url.non_relative() {
Err(ParseError::RelativeUrlWithNonRelativeBase)
} else {
let scheme_type = SchemeType::from(base_url.scheme());
@@ -200,7 +200,7 @@ impl<'a> Parser<'a> {
if slashes_count < 2 &&
base_url.scheme() == &self.serialization[..scheme_end as usize] {
// Non-relative URLs only happen with "not special" schemes.
debug_assert!(!base_url.non_relative);
debug_assert!(!base_url.non_relative());
self.serialization.clear();
return self.parse_relative(input, scheme_type, base_url)
}
@@ -227,15 +227,14 @@ impl<'a> Parser<'a> {
let host_end = path_start;
let host = HostInternal::None;
let port = None;
let relative = input.starts_with("/");
let remaining = if relative {
let remaining = if input.starts_with("/") {
let path_start = self.serialization.len();
self.serialization.push('/');
self.parse_path(scheme_type, &mut false, path_start, &input[1..])
} else {
self.parse_non_relative_path(input)
};
self.with_query_and_fragment(!relative, scheme_end, username_end, host_start,
self.with_query_and_fragment(scheme_end, username_end, host_start,
host_end, host, port, path_start, remaining)
}

@@ -263,7 +262,6 @@ impl<'a> Parser<'a> {
let path_start = "file://".len() as u32;
Ok(Url {
serialization: self.serialization,
non_relative: false,
scheme_end: scheme_end,
username_end: path_start,
host_start: path_start,
@@ -301,7 +299,6 @@ impl<'a> Parser<'a> {
try!(self.parse_query_and_fragment(scheme_end, input));
Ok(Url {
serialization: self.serialization,
non_relative: false,
scheme_end: scheme_end,
username_end: path_start,
host_start: path_start,
@@ -325,7 +322,6 @@ impl<'a> Parser<'a> {
self.parse_fragment(&input[1..]);
Ok(Url {
serialization: self.serialization,
non_relative: false,
scheme_end: scheme_end,
username_end: path_start,
host_start: path_start,
@@ -364,7 +360,6 @@ impl<'a> Parser<'a> {
try!(self.parse_query_and_fragment(scheme_end, remaining));
Ok(Url {
serialization: self.serialization,
non_relative: false,
scheme_end: scheme_end,
username_end: host_start,
host_start: host_start,
@@ -394,7 +389,6 @@ impl<'a> Parser<'a> {
let path_start = path_start as u32;
Ok(Url {
serialization: self.serialization,
non_relative: false,
scheme_end: scheme_end,
username_end: path_start,
host_start: path_start,
@@ -421,9 +415,8 @@ impl<'a> Parser<'a> {
self.pop_path(SchemeType::File, base_url.path_start as usize);
let remaining = self.parse_path(
SchemeType::File, &mut true, base_url.path_start as usize, input);
let non_relative = false;
self.with_query_and_fragment(
non_relative, base_url.scheme_end, base_url.username_end, base_url.host_start,
base_url.scheme_end, base_url.username_end, base_url.host_start,
base_url.host_end, base_url.host, base_url.port, base_url.path_start, remaining)
} else {
self.serialization.push_str("file:///");
@@ -436,7 +429,6 @@ impl<'a> Parser<'a> {
let path_start = path_start as u32;
Ok(Url {
serialization: self.serialization,
non_relative: false,
scheme_end: scheme_end,
username_end: path_start,
host_start: path_start,
@@ -502,9 +494,8 @@ impl<'a> Parser<'a> {
self.serialization.push_str(base_url.slice(..path_start + 1));
let remaining = self.parse_path(
scheme_type, &mut true, path_start as usize, &input[1..]);
let non_relative = false;
self.with_query_and_fragment(
non_relative, base_url.scheme_end, base_url.username_end, base_url.host_start,
base_url.scheme_end, base_url.username_end, base_url.host_start,
base_url.host_end, base_url.host, base_url.port, base_url.path_start, remaining)
}
_ => {
@@ -518,9 +509,8 @@ impl<'a> Parser<'a> {
self.pop_path(scheme_type, base_url.path_start as usize);
let remaining = self.parse_path(
scheme_type, &mut true, base_url.path_start as usize, input);
let non_relative = false;
self.with_query_and_fragment(
non_relative, base_url.scheme_end, base_url.username_end, base_url.host_start,
base_url.scheme_end, base_url.username_end, base_url.host_start,
base_url.host_end, base_url.host, base_url.port, base_url.path_start, remaining)
}
}
@@ -530,7 +520,6 @@ impl<'a> Parser<'a> {
-> ParseResult<Url> {
self.serialization.push('/');
self.serialization.push('/');
let non_relative = false;
// authority state
let (username_end, remaining) = try!(self.parse_userinfo(input, scheme_type));
// host state
@@ -541,7 +530,7 @@ impl<'a> Parser<'a> {
let path_start = try!(to_u32(self.serialization.len()));
let remaining = self.parse_path_start(
scheme_type, &mut true, remaining);
self.with_query_and_fragment(non_relative, scheme_end, username_end, host_start,
self.with_query_and_fragment(scheme_end, username_end, host_start,
host_end, host, port, path_start, remaining)
}

@@ -857,15 +846,14 @@ impl<'a> Parser<'a> {
""
}

fn with_query_and_fragment(mut self, non_relative: bool, scheme_end: u32, username_end: u32,
fn with_query_and_fragment(mut self, scheme_end: u32, username_end: u32,
host_start: u32, host_end: u32, host: HostInternal,
port: Option<u16>, path_start: u32, remaining: &str)
-> ParseResult<Url> {
let (query_start, fragment_start) =
try!(self.parse_query_and_fragment(scheme_end, remaining));
Ok(Url {
serialization: self.serialization,
non_relative: non_relative,
scheme_end: scheme_end,
username_end: username_end,
host_start: host_start,
@@ -104,13 +104,12 @@ impl Url {

Position::AfterScheme => self.scheme_end as usize,

Position::BeforeUsername => if self.non_relative {
Position::BeforeUsername => if self.slice(self.scheme_end..).starts_with("://") {
self.scheme_end as usize + "://".len()
} else {
debug_assert!(self.byte_at(self.scheme_end) == b':');
debug_assert!(self.scheme_end + ":".len() as u32 == self.username_end);
self.scheme_end as usize + ":".len()
} else {
debug_assert!(self.slice(self.scheme_end..).starts_with("://"));
self.scheme_end as usize + "://".len()
},

Position::AfterUsername => self.username_end as usize,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.