소스 검색

Add idna::domain_to_ascii_strict

Simon Sapin 7 년 전
부모
커밋
7371286087
1개의 변경된 파일11개의 추가작업 그리고 2개의 파일을 삭제
  1. 11 2
      idna/src/lib.rs

+ 11 - 2
idna/src/lib.rs

@@ -50,7 +50,16 @@ pub use uts46::{Config, Errors};
 ///
 ///
 /// This process may fail.
 /// This process may fail.
 pub fn domain_to_ascii(domain: &str) -> Result<String, uts46::Errors> {
 pub fn domain_to_ascii(domain: &str) -> Result<String, uts46::Errors> {
-    uts46::Config::default().to_ascii(domain)
+    Config::default().to_ascii(domain)
+}
+
+/// The [domain to ASCII](https://url.spec.whatwg.org/#concept-domain-to-ascii) algorithm,
+/// with the `beStrict` flag set.
+pub fn domain_to_ascii_strict(domain: &str) -> Result<String, uts46::Errors> {
+    Config::default()
+        .use_std3_ascii_rules(true)
+        .verify_dns_length(true)
+        .to_ascii(domain)
 }
 }
 
 
 /// The [domain to Unicode](https://url.spec.whatwg.org/#concept-domain-to-unicode) algorithm.
 /// 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> {
 /// This may indicate [syntax violations](https://url.spec.whatwg.org/#syntax-violation)
 /// This may indicate [syntax violations](https://url.spec.whatwg.org/#syntax-violation)
 /// but always returns a string for the mapped domain.
 /// but always returns a string for the mapped domain.
 pub fn domain_to_unicode(domain: &str) -> (String, Result<(), uts46::Errors>) {
 pub fn domain_to_unicode(domain: &str) -> (String, Result<(), uts46::Errors>) {
-    uts46::Config::default().to_unicode(domain)
+    Config::default().to_unicode(domain)
 }
 }