Skip to content

Commit 7371286

Browse files
committed
Add idna::domain_to_ascii_strict
1 parent 62cc614 commit 7371286

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

idna/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ pub use uts46::{Config, Errors};
5050
///
5151
/// This process may fail.
5252
pub fn domain_to_ascii(domain: &str) -> Result<String, uts46::Errors> {
53-
uts46::Config::default().to_ascii(domain)
53+
Config::default().to_ascii(domain)
54+
}
55+
56+
/// The [domain to ASCII](https://url.spec.whatwg.org/#concept-domain-to-ascii) algorithm,
57+
/// with the `beStrict` flag set.
58+
pub fn domain_to_ascii_strict(domain: &str) -> Result<String, uts46::Errors> {
59+
Config::default()
60+
.use_std3_ascii_rules(true)
61+
.verify_dns_length(true)
62+
.to_ascii(domain)
5463
}
5564

5665
/// The [domain to Unicode](https://url.spec.whatwg.org/#concept-domain-to-unicode) algorithm.
@@ -62,5 +71,5 @@ pub fn domain_to_ascii(domain: &str) -> Result<String, uts46::Errors> {
6271
/// This may indicate [syntax violations](https://url.spec.whatwg.org/#syntax-violation)
6372
/// but always returns a string for the mapped domain.
6473
pub fn domain_to_unicode(domain: &str) -> (String, Result<(), uts46::Errors>) {
65-
uts46::Config::default().to_unicode(domain)
74+
Config::default().to_unicode(domain)
6675
}

0 commit comments

Comments
 (0)