arti-client: Reject .onion, when we should, without allocating

Use new strip_suffix_ignore_ascii_case
This commit is contained in:
Ian Jackson 2023-03-08 16:22:24 +00:00
parent 8d031a7147
commit 6540f260b5
1 changed files with 2 additions and 1 deletions

View File

@ -5,6 +5,7 @@ use crate::err::ErrorDetail;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use std::str::FromStr;
use thiserror::Error;
use tor_basic_utils::StrExt;
// ----------------------------------------------------------------------
@ -178,7 +179,7 @@ impl TorAddr {
if !is_valid_hostname(addr) {
return Err(ErrorDetail::InvalidHostname);
}
if addr.to_lowercase().ends_with(".onion") {
if addr.strip_suffix_ignore_ascii_case(".onion").is_some() {
// TODO hs: Allow this in some cases instead.
return Err(ErrorDetail::OnionAddressNotSupported);
}