#[inline]
pub fn is_external_link(url: &[u8]) -> bool {
let first_char = match url.first() {
Some(x) => x,
None => return false,
};
if url.starts_with(b"//") {
return true;
}
if !first_char.is_ascii_alphabetic() {
return false;
}
for c in &url[1..] {
match c {
b'a'..=b'z' => (),
b'A'..=b'Z' => (),
b'0'..=b'9' => (),
b'+' => (),
b'-' => (),
b'.' => (),
b':' => return true,
_ => return false,
}
}
false
}
#[test]
fn test_is_bad_schema() {
assert!(is_external_link(b"//"));
assert!(!is_external_link(b""));
assert!(!is_external_link(b"http"));
assert!(is_external_link(b"http:"));
assert!(is_external_link(b"http:/"));
assert!(!is_external_link(b"http/"));
}