Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a8977a8
Reimplement idna on top of ICU4X
hsivonen Feb 14, 2024
09765af
Add an even faster lower-case ASCII letter path to avoid regressing p…
hsivonen Mar 20, 2024
7e929ce
Comments and verify_dns_length tweak
hsivonen Mar 21, 2024
f413387
Parametrize internal vs. external Punycode caller; restore external A…
hsivonen Mar 21, 2024
71c03b9
Add bench for to_ascii on an already-Punycode name
hsivonen Mar 21, 2024
9af00cb
Avoid re-encoding Punycode when possible
hsivonen Mar 21, 2024
dc8f301
Pass through the input slice in many more cases
hsivonen Mar 21, 2024
41e0192
Add testing for the simultaneous mode
hsivonen Mar 21, 2024
41f2107
Omit the invalid domain character check on the url side
hsivonen Mar 21, 2024
4d7d41a
Document that Punycode labels must result in non-ASCII
hsivonen Mar 21, 2024
98ca752
Rename files called uts46.rs to deprecated.rs
hsivonen Mar 21, 2024
4bbabe9
Rename uts46bis to uts46
hsivonen Mar 21, 2024
7dc0082
Tweak docs
hsivonen Mar 21, 2024
f8eb96e
Avoid useless copying and useless UTF-8 decode
hsivonen Apr 11, 2024
eb6e3d5
Use inline(never) to optimize binary size
hsivonen Apr 15, 2024
ce3d4d1
Split CheckHyphens into a separate concern form the ASCII deny list
hsivonen Apr 16, 2024
6672161
Make the ASCII deny list customizable
hsivonen Apr 18, 2024
90fe4b3
Better docs and top-level functions
hsivonen Apr 18, 2024
50381ff
Parameter for VerifyDNSLength
hsivonen Apr 18, 2024
8268c5a
Restore support for transitional processing to minimize breakage
hsivonen Apr 18, 2024
999bef4
In the deprecated API, use empty deny list with use_std3_ascii_rules=…
hsivonen Apr 18, 2024
b277c85
Tweak docs
hsivonen Apr 18, 2024
980348c
Docs, rename AsciiDenyList::WHATWG to ::URL, tweak top-level functions
hsivonen Apr 19, 2024
4efd589
Use idna crate top-level function in the url crate to dogfood the top…
hsivonen Apr 22, 2024
da6cf50
Add an Usage section to the README
hsivonen Apr 24, 2024
d938024
Add an early return to map_transitional for readability
hsivonen Apr 26, 2024
679edb9
Document internal vs. external Punycode caller differences
hsivonen Apr 26, 2024
4f605c9
Per discussion with Valentin, revert deprecated API to the old behavi…
hsivonen May 3, 2024
bbf4308
Add comments about not fixing deprecated API
hsivonen May 3, 2024
e842dae
Merge branch 'main' into icu4x
hsivonen May 3, 2024
6690c49
Add a comment explaining FailFast in deprecated.rs
hsivonen May 3, 2024
38cedad
For future-proofing, add compiled_data cargo feature (currently alway…
hsivonen May 3, 2024
52137e7
Remove remark about spec violation by making root dot permissibility …
hsivonen May 20, 2024
081f44b
Clarify README about IDNA 2003/2008
hsivonen May 20, 2024
aaa7a40
Add a historical remark to the README
hsivonen May 20, 2024
8b03034
Fix typo
hsivonen May 20, 2024
c8a4bd3
Depend on crates.io versions of icu_normalizer and icu_properties
hsivonen May 23, 2024
be3db8e
Address clippy lints
hsivonen May 23, 2024
6020673
Update versions
hsivonen May 23, 2024
245c514
Increment dependency versions
hsivonen May 29, 2024
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
Prev Previous commit
Next Next commit
Avoid useless copying and useless UTF-8 decode
  • Loading branch information
hsivonen committed Apr 11, 2024
commit f8eb96ed801e7d46b61807f914e9cfb32f9d0d35
11 changes: 7 additions & 4 deletions url/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::borrow::Cow;
use std::cmp;
use std::fmt::{self, Formatter};
use std::net::{Ipv4Addr, Ipv6Addr};
Expand Down Expand Up @@ -81,7 +82,7 @@ impl Host<String> {
}
return parse_ipv6addr(&input[1..input.len() - 1]).map(Host::Ipv6);
}
let domain = percent_decode(input.as_bytes()).decode_utf8_lossy();
let domain: Cow<'_, [u8]> = percent_decode(input.as_bytes()).into();

let domain = Self::domain_to_ascii(&domain)?;

Expand All @@ -93,7 +94,7 @@ impl Host<String> {
let address = parse_ipv4addr(&domain)?;
Ok(Host::Ipv4(address))
} else {
Ok(Host::Domain(domain))
Ok(Host::Domain(domain.to_string()))
}
}

Expand Down Expand Up @@ -138,8 +139,10 @@ impl Host<String> {
}

/// convert domain with idna
fn domain_to_ascii(domain: &str) -> Result<String, ParseError> {
idna::domain_to_ascii(domain).map_err(Into::into)
fn domain_to_ascii(domain: &[u8]) -> Result<Cow<'_, str>, ParseError> {
idna::uts46::Uts46::new()
.to_ascii(domain, idna::uts46::Strictness::WhatwgUserAgent)
.map_err(Into::into)
}
}

Expand Down