aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-05-16 21:05:00 +0000
committerGitHub <noreply@github.com>2019-05-16 21:05:00 +0000
commitd934df6c0e2279aa386fc2aa4154195e7b13ce64 (patch)
tree878a461562dad01ab1f91260538cdbdd8fa708bd
parent2a6e9843eaa583b67d9b853f396dd72e69a20585 (diff)
downloadalacritty-d934df6c0e2279aa386fc2aa4154195e7b13ce64.tar.gz
alacritty-d934df6c0e2279aa386fc2aa4154195e7b13ce64.zip
Fix URL detection matching invalid URLs
Fixes #2450.
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty_terminal/src/url.rs28
2 files changed, 19 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1713bf38..b902ebba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Mouse mode generating events when the cell has not changed
- Selections not automatically expanding across double-width characters
- On macOS, automatic graphics switching has been enabled again
+- Text getting recognized as URLs without slashes separating the scheme
### Removed
diff --git a/alacritty_terminal/src/url.rs b/alacritty_terminal/src/url.rs
index 088cf657..7f47e12d 100644
--- a/alacritty_terminal/src/url.rs
+++ b/alacritty_terminal/src/url.rs
@@ -13,14 +13,14 @@
// limitations under the License.
use unicode_width::UnicodeWidthChar;
-use url;
use crate::term::cell::{Cell, Flags};
// See https://tools.ietf.org/html/rfc3987#page-13
const URL_SEPARATOR_CHARS: [char; 10] = ['<', '>', '"', ' ', '{', '}', '|', '\\', '^', '`'];
const URL_DENY_END_CHARS: [char; 8] = ['.', ',', ';', ':', '?', '!', '/', '('];
-const URL_SCHEMES: [&str; 8] = ["http", "https", "mailto", "news", "file", "git", "ssh", "ftp"];
+const URL_SCHEMES: [&str; 8] =
+ ["http://", "https://", "mailto:", "news:", "file://", "git://", "ssh://", "ftp://"];
/// URL text and origin of the original click position.
#[derive(Debug, PartialEq)]
@@ -117,16 +117,15 @@ impl UrlParser {
}
// Check if string is valid url
- match url::Url::parse(&self.state) {
- Ok(url) => {
- if URL_SCHEMES.contains(&url.scheme()) && self.origin > 0 {
- Some(Url { origin: self.origin - 1, text: self.state })
- } else {
- None
+ if self.origin > 0 && url::Url::parse(&self.state).is_ok() {
+ for scheme in &URL_SCHEMES {
+ if self.state.starts_with(scheme) {
+ return Some(Url { origin: self.origin - 1, text: self.state });
}
- },
- Err(_) => None,
+ }
}
+
+ None
}
fn advance(&mut self, c: char, pos: usize) -> bool {
@@ -305,5 +304,14 @@ mod tests {
url_test("git://example.org", "git://example.org");
url_test("ssh://example.org", "ssh://example.org");
url_test("ftp://example.org", "ftp://example.org");
+
+ assert_eq!(url_create_term("mailto.example.org").url_search(Point::default()), None);
+ assert_eq!(url_create_term("https:example.org").url_search(Point::default()), None);
+ assert_eq!(url_create_term("http:example.org").url_search(Point::default()), None);
+ assert_eq!(url_create_term("news.example.org").url_search(Point::default()), None);
+ assert_eq!(url_create_term("file:example.org").url_search(Point::default()), None);
+ assert_eq!(url_create_term("git:example.org").url_search(Point::default()), None);
+ assert_eq!(url_create_term("ssh:example.org").url_search(Point::default()), None);
+ assert_eq!(url_create_term("ftp:example.org").url_search(Point::default()), None);
}
}