diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-20 12:35:14 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-20 12:35:14 -0600 |
commit | ac6a2681ae9f94827ebd989c3d3c3b175cbb455f (patch) | |
tree | 8d3b871f1c46d38ef32759b2c03145451c6f9d67 | |
parent | 68b1d1d2860ac6c6e8c1c0dfe46af6790ca01dc8 (diff) | |
parent | 0818b4445963871b5efbf2558c624523c59387d1 (diff) | |
download | servo-ac6a2681ae9f94827ebd989c3d3c3b175cbb455f.tar.gz servo-ac6a2681ae9f94827ebd989c3d3c3b175cbb455f.zip |
Auto merge of #14274 - stshine:servo-url-index, r=emilio
Implement range index with the Position enum on ServoUrl
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
r? @emilio
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14274)
<!-- Reviewable:end -->
-rw-r--r-- | components/net/data_loader.rs | 2 | ||||
-rw-r--r-- | components/net/http_loader.rs | 2 | ||||
-rw-r--r-- | components/script/dom/response.rs | 2 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 2 | ||||
-rw-r--r-- | components/script/script_thread.rs | 2 | ||||
-rw-r--r-- | components/url/lib.rs | 31 |
6 files changed, 35 insertions, 6 deletions
diff --git a/components/net/data_loader.rs b/components/net/data_loader.rs index 19a6c92f0e2..7c26efac2a9 100644 --- a/components/net/data_loader.rs +++ b/components/net/data_loader.rs @@ -35,7 +35,7 @@ pub type DecodeData = (Mime, Vec<u8>); pub fn decode(url: &ServoUrl) -> Result<DecodeData, DecodeError> { assert_eq!(url.scheme(), "data"); // Split out content type and data. - let parts: Vec<&str> = url.as_url().unwrap()[Position::BeforePath..Position::AfterQuery].splitn(2, ',').collect(); + let parts: Vec<&str> = url[Position::BeforePath..Position::AfterQuery].splitn(2, ',').collect(); if parts.len() != 2 { return Err(DecodeError::InvalidDataUri); } diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 88826f9ed15..f40934d5e7c 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -931,7 +931,7 @@ pub fn load<A, B>(load_data: &LoadData, // the source rather than rendering the contents of the URL. let viewing_source = doc_url.scheme() == "view-source"; if viewing_source { - doc_url = ServoUrl::parse(&load_data.url.as_url().unwrap()[Position::BeforeUsername..]).unwrap(); + doc_url = ServoUrl::parse(&load_data.url[Position::BeforeUsername..]).unwrap(); } // Loop to handle redirects. diff --git a/components/script/dom/response.rs b/components/script/dom/response.rs index 484a1d0beee..949bfdb0d47 100644 --- a/components/script/dom/response.rs +++ b/components/script/dom/response.rs @@ -358,7 +358,7 @@ impl ResponseMethods for Response { } fn serialize_without_fragment(url: &ServoUrl) -> &str { - &url.as_url().unwrap()[..Position::AfterQuery] + &url[..Position::AfterQuery] } impl Response { diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 493e99cc957..a89c5c51799 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -878,7 +878,7 @@ impl XMLHttpRequest { }, }; - *self.response_url.borrow_mut() = metadata.final_url.as_url().unwrap()[..Position::AfterQuery].to_owned(); + *self.response_url.borrow_mut() = metadata.final_url[..Position::AfterQuery].to_owned(); // XXXManishearth Clear cache entries in case of a network error self.process_partial_response(XHRProgress::HeadersReceived( diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 30462f3823b..9b00846dbb3 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1739,7 +1739,7 @@ impl ScriptThread { // Start with the scheme data of the parsed URL; // append question mark and query component, if any; // append number sign and fragment component if any. - let encoded = &incomplete.url.as_url().unwrap()[Position::BeforePath..]; + let encoded = &incomplete.url[Position::BeforePath..]; // Percent-decode (8.) and UTF-8 decode (9.) let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy(); diff --git a/components/url/lib.rs b/components/url/lib.rs index c0a02fff9f6..415b2dd4ea6 100644 --- a/components/url/lib.rs +++ b/components/url/lib.rs @@ -19,9 +19,10 @@ extern crate url; use std::fmt; use std::net::IpAddr; +use std::ops::{Range, RangeFrom, RangeTo, RangeFull, Index}; use std::path::Path; use std::sync::Arc; -use url::{Url, Origin}; +use url::{Url, Origin, Position}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "servo", derive(HeapSizeOf, Serialize, Deserialize))] @@ -152,3 +153,31 @@ impl fmt::Display for ServoUrl { self.0.fmt(formatter) } } + +impl Index<RangeFull> for ServoUrl { + type Output = str; + fn index(&self, _: RangeFull) -> &str { + &self.0[..] + } +} + +impl Index<RangeFrom<Position>> for ServoUrl { + type Output = str; + fn index(&self, range: RangeFrom<Position>) -> &str { + &self.0[range] + } +} + +impl Index<RangeTo<Position>> for ServoUrl { + type Output = str; + fn index(&self, range: RangeTo<Position>) -> &str { + &self.0[range] + } +} + +impl Index<Range<Position>> for ServoUrl { + type Output = str; + fn index(&self, range: Range<Position>) -> &str { + &self.0[range] + } +} |