From 902fd3a9fb58e52085110b2f8e0ec9c282d8b2a2 Mon Sep 17 00:00:00 2001 From: Katie Watson Date: Tue, 14 Feb 2023 04:20:41 -0800 Subject: [PATCH] Allow external links to start with "www.*" (#2100) * Make www.* URLs considered valid external links * Tweak description of is_external_link --- components/markdown/src/markdown.rs | 1 + components/utils/src/net.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/markdown/src/markdown.rs b/components/markdown/src/markdown.rs index d773a21f..4677cc93 100644 --- a/components/markdown/src/markdown.rs +++ b/components/markdown/src/markdown.rs @@ -593,6 +593,7 @@ mod tests { fn test_is_external_link() { assert!(is_external_link("http://example.com/")); assert!(is_external_link("https://example.com/")); + assert!(is_external_link("www.example.com")); assert!(is_external_link("https://example.com/index.html#introduction")); assert!(!is_external_link("mailto:user@example.com")); diff --git a/components/utils/src/net.rs b/components/utils/src/net.rs index 9f662e85..61deeae3 100644 --- a/components/utils/src/net.rs +++ b/components/utils/src/net.rs @@ -10,7 +10,7 @@ pub fn port_is_available(port: u16) -> bool { TcpListener::bind(("127.0.0.1", port)).is_ok() } -/// Returns whether a link starts with an HTTP(s) scheme. +/// Returns whether a link starts with an HTTP(s) scheme or "www.". pub fn is_external_link(link: &str) -> bool { - link.starts_with("http:") || link.starts_with("https:") + link.starts_with("http:") || link.starts_with("https:") || link.starts_with("www.") }