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

Update tests from https://github.com/w3c/web-platform-tests/blob/mast…

…er/url/

Parser changes correspond to spec changes.
  • Loading branch information
SimonSapin committed Mar 3, 2016
commit ca9f87dc42d84682cf64e68fbd3416835b93036b
@@ -343,7 +343,10 @@ impl Url {
}
}

/// Return this URL’s fragment identifier, if any, as a percent-encoded ASCII string.
/// Return this URL’s fragment identifier, if any.
///
/// **Note:** the parser does *not* percent-encode this component,
/// but the input may be percent-encoded already.
pub fn fragment(&self) -> Option<&str> {
self.fragment_start.map(|start| {
debug_assert!(self.byte_at(start) == b'#');
@@ -794,22 +794,30 @@ impl<'a> Parser<'a> {
'\t' | '\n' | '\r' => self.syntax_violation("invalid characters"),
_ => {
self.check_url_code_point(input, i, c);
if c == '%' {
let after_percent_sign = iter.clone();
if matches!(iter.next(), Some((_, '2', _))) &&
matches!(iter.next(), Some((_, 'E', _)) | Some((_, 'e', _))) {
self.serialization.push('.');
continue
}
iter = after_percent_sign
}
self.serialization.extend(utf8_percent_encode(
&input[i..next_i], DEFAULT_ENCODE_SET));
}
}
}
match &self.serialization[segment_start..] {
".." | ".%2e" | ".%2E" | "%2e." | "%2E." |
"%2e%2e" | "%2E%2e" | "%2e%2E" | "%2E%2E" => {
".." => {
debug_assert!(self.serialization.as_bytes()[segment_start - 1] == b'/');
self.serialization.truncate(segment_start - 1); // Truncate "/.."
self.pop_path(scheme_type, path_start);
if !self.serialization[path_start..].ends_with("/") {
self.serialization.push('/')
}
},
"." | "%2e" | "%2E" => {
"." => {
self.serialization.truncate(segment_start);
},
_ => {
@@ -964,13 +972,12 @@ impl<'a> Parser<'a> {
}

pub fn parse_fragment(&mut self, input: &str) {
for (i, c, next_i) in input.char_ranges() {
for (i, c) in input.char_indices() {
match c {
'\0' | '\t' | '\n' | '\r' => self.syntax_violation("invalid character"),
_ => {
self.check_url_code_point(input, i, c);
self.serialization.extend(utf8_percent_encode(
&input[i..next_i], SIMPLE_ENCODE_SET));
self.serialization.push(c); // No percent-encoding here.
}
}
}
@@ -1039,6 +1046,7 @@ impl<'a> StrCharRanges<'a> for &'a str {
}
}

#[derive(Clone)]
pub struct CharRanges<'a> {
slice: &'a str,
position: usize,
@@ -32,13 +32,13 @@ impl WebIdl {
}

/// **Not implemented yet** Getter for https://url.spec.whatwg.org/#dom-url-origin
pub fn get_origin(_url: &Url) -> String {
pub fn origin(_url: &Url) -> String {
unimplemented!() // FIXME
}

/// Getter for https://url.spec.whatwg.org/#dom-url-protocol
#[inline]
pub fn get_protocol(url: &Url) -> &str {
pub fn protocol(url: &Url) -> &str {
debug_assert!(url.byte_at(url.scheme_end) == b':');
url.slice(..url.scheme_end + 1)
}
@@ -50,7 +50,7 @@ impl WebIdl {

/// Getter for https://url.spec.whatwg.org/#dom-url-username
#[inline]
pub fn get_username(url: &Url) -> &str {
pub fn username(url: &Url) -> &str {
url.username()
}

@@ -61,7 +61,7 @@ impl WebIdl {

/// Getter for https://url.spec.whatwg.org/#dom-url-password
#[inline]
pub fn get_password(url: &Url) -> &str {
pub fn password(url: &Url) -> &str {
url.password().unwrap_or("")
}

@@ -72,9 +72,8 @@ impl WebIdl {

/// Getter for https://url.spec.whatwg.org/#dom-url-host
#[inline]
pub fn get_host(url: &Url) -> &str {
let host = url.slice(url.host_start..url.host_end);
debug_assert!(!host.is_empty() || url.non_relative);
pub fn host(url: &Url) -> &str {
let host = url.slice(url.host_start..url.path_start);
host
}

@@ -85,7 +84,7 @@ impl WebIdl {

/// Getter for https://url.spec.whatwg.org/#dom-url-hostname
#[inline]
pub fn get_hostname(url: &Url) -> &str {
pub fn hostname(url: &Url) -> &str {
url.host_str().unwrap_or("")
}

@@ -96,7 +95,7 @@ impl WebIdl {

/// Getter for https://url.spec.whatwg.org/#dom-url-port
#[inline]
pub fn get_port(url: &Url) -> &str {
pub fn port(url: &Url) -> &str {
if url.port.is_some() {
debug_assert!(url.byte_at(url.host_end) == b':');
url.slice(url.host_end + 1..url.path_start)
@@ -112,7 +111,7 @@ impl WebIdl {

/// Getter for https://url.spec.whatwg.org/#dom-url-pathname
#[inline]
pub fn get_pathname(url: &Url) -> &str {
pub fn pathname(url: &Url) -> &str {
url.path()
}

@@ -122,13 +121,21 @@ impl WebIdl {
}

/// Getter for https://url.spec.whatwg.org/#dom-url-search
pub fn get_search(url: &Url) -> &str {
pub fn search(url: &Url) -> &str {
match (url.query_start, url.fragment_start) {
(None, _) => "",
(Some(query_start), None) => url.slice(query_start..),
(Some(query_start), Some(fragment_start)) => {
url.slice(query_start..fragment_start)
}
(Some(query_start), None) if {
debug_assert!(url.byte_at(query_start) == b'?');
// If the query (after ?) is not empty
(query_start as usize) < url.serialization.len() - 1
} => url.slice(query_start..),

(Some(query_start), Some(fragment_start)) if {
debug_assert!(url.byte_at(query_start) == b'?');
// If the fragment (after ?) is not empty
query_start < fragment_start
} => url.slice(query_start..fragment_start),

_ => "",
}
}

@@ -138,15 +145,19 @@ impl WebIdl {
}

/// **Not implemented yet** Getter for https://url.spec.whatwg.org/#dom-url-searchparams
pub fn get_search_params(_url: &Url) -> Vec<(String, String)> {
pub fn search_params(_url: &Url) -> Vec<(String, String)> {
unimplemented!(); // FIXME
}

/// Getter for https://url.spec.whatwg.org/#dom-url-hash
pub fn get_hash(url: &Url) -> &str {
pub fn hash(url: &Url) -> &str {
match url.fragment_start {
Some(start) => url.slice(start..),
None => "",
Some(start) if {
debug_assert!(url.byte_at(start) == b'#');
// If the fragment (after #) is not empty
(start as usize) < url.serialization.len() - 1
} => url.slice(start..),
_ => "",
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.