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
18 changes: 13 additions & 5 deletions src/content_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ impl TryFrom<NetworkFilter> for CbRuleEquivalent {
} else {
// The network filter has already parsed successfully, so this should be
// safe
idna::domain_to_ascii(&lowercase).unwrap()
idna::domain_to_ascii_cow(&lowercase.as_bytes(), idna::AsciiDenyList::EMPTY)
.unwrap()
.to_string()
};

collection.push(format!("*{normalized_domain}"));
Expand Down Expand Up @@ -616,13 +618,19 @@ impl TryFrom<CosmeticFilter> for CbRule {
any_unsupported = true
}
LocationType::Hostname => {
if let Ok(encoded) = idna::domain_to_ascii(location) {
hostnames_vec.push(encoded);
if let Ok(encoded) = idna::domain_to_ascii_cow(
location.as_bytes(),
idna::AsciiDenyList::EMPTY,
) {
hostnames_vec.push(encoded.to_string());
}
}
LocationType::NotHostname => {
if let Ok(encoded) = idna::domain_to_ascii(location) {
not_hostnames_vec.push(encoded);
if let Ok(encoded) = idna::domain_to_ascii_cow(
location.as_bytes(),
idna::AsciiDenyList::EMPTY,
) {
not_hostnames_vec.push(encoded.to_string());
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/filters/cosmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl CosmeticFilter {
if location.is_ascii() {
hostname.push_str(location);
} else {
match idna::domain_to_ascii(location) {
match idna::domain_to_ascii_cow(location.as_bytes(), idna::AsciiDenyList::EMPTY) {
Ok(x) if !x.is_empty() => hostname.push_str(&x),
_ => return Err(CosmeticFilterError::PunycodeError),
}
Expand Down
3 changes: 2 additions & 1 deletion src/url_parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ impl Parser {
if host_str.is_ascii() {
write!(&mut self.serialization, "{host_str}").unwrap();
} else {
let encoded = idna::domain_to_ascii(host_str)?;
let encoded =
idna::domain_to_ascii_cow(host_str.as_bytes(), idna::AsciiDenyList::EMPTY)?;
write!(&mut self.serialization, "{encoded}").unwrap();
}

Expand Down