summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSander van Harmelen <sander@xanzy.io>2019-01-28 19:28:51 +0100
committerChristian Duerr <chrisduerr@users.noreply.github.com>2019-01-28 18:28:51 +0000
commit3562f2c9aacb4b7cba8a61d95f4d325b6b5887c1 (patch)
treea27dc3208664e09f8abda1ceffda6a4a3e522df1 /src
parente95c80764e513588b8af6e3fa03b5edb9ec6a03e (diff)
downloadalacritty-3562f2c9aacb4b7cba8a61d95f4d325b6b5887c1.tar.gz
alacritty-3562f2c9aacb4b7cba8a61d95f4d325b6b5887c1.zip
Trim unicode characters from the start of URLs
Diffstat (limited to 'src')
-rw-r--r--src/url.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/url.rs b/src/url.rs
index fc2a00f9..0db083be 100644
--- a/src/url.rs
+++ b/src/url.rs
@@ -45,13 +45,19 @@ impl UrlParser {
/// Returns the URL if the parser has found any.
pub fn url(mut self) -> Option<String> {
- // Remove non-alphabetical characters before scheme
+ // Remove non-alphabetical characters before the scheme
+ // https://tools.ietf.org/html/rfc3986#section-3.1
if let Some(index) = self.state.find("://") {
- for i in (0..index - 1).rev() {
- match self.state.chars().nth(i).unwrap() {
+ let iter = self
+ .state
+ .char_indices()
+ .rev()
+ .skip_while(|(byte_index, _)| *byte_index >= index);
+ for (byte_index, c) in iter {
+ match c {
'a'...'z' | 'A'...'Z' => (),
_ => {
- self.state = self.state.split_off(i + 1);
+ self.state = self.state.split_off(byte_index + c.len_utf8());
break;
}
}
@@ -206,6 +212,7 @@ mod tests {
url_test("complicated:https://example.org", "https://example.org", 15);
url_test("test.https://example.org", "https://example.org", 10);
url_test(",https://example.org", "https://example.org", 5);
+ url_test("\u{2502}https://example.org", "https://example.org", 5);
}
#[test]