Skip to content

Commit

Permalink
Allow external links to start with "www.*" (#2100)
Browse files Browse the repository at this point in the history
* Make www.* URLs considered valid external links

* Tweak description of is_external_link
  • Loading branch information
pqcfox authored and Keats committed Feb 16, 2023
1 parent bc27c01 commit 902fd3a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/markdown/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]"));
Expand Down
4 changes: 2 additions & 2 deletions components/utils/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

0 comments on commit 902fd3a

Please sign in to comment.