Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ pub(crate) fn find_authority_end(
let mut chars = s.char_indices();

while let Some((i, c)) = chars.next() {
if require_host && !userinfo_allowed && !maybe_host {
break;
}
let can_be_last = match c {
// ALPHA
'a'..='z' | 'A'..='Z' | '\u{80}'..=char::MAX => {
Expand Down
9 changes: 9 additions & 0 deletions tests/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ pub fn test_international_allowed() {
assert_eq!(link.as_str(), "\u{A1}\u{A2}example.com");
}

#[test]
fn no_quadratic_scan_of_schemeless_hosts() {
// Each `~` makes the current candidate invalid as a host. Scanning has to stop there
// instead of running to the end of the input for every candidate, otherwise this test
// takes hours instead of milliseconds.
let input = "a.a~".repeat(2_000_000);
assert_not_linked(&input);
}

fn assert_linked(input: &str, expected: &str) {
let mut finder = LinkFinder::new();
finder.url_must_have_scheme(false);
Expand Down