From 065ece220e2732f35672a6c23a4504d7e4761232 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 11 Feb 2019 13:28:37 +0100 Subject: [PATCH] Introduce Config::check_hyphens in uts46 --- idna/src/uts46.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/idna/src/uts46.rs b/idna/src/uts46.rs index b4f78b0a5..7b478005b 100644 --- a/idna/src/uts46.rs +++ b/idna/src/uts46.rs @@ -253,11 +253,9 @@ fn validate(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec< // NOTE: Spec says that the label must not contain a HYPHEN-MINUS character in both the // third and fourth positions. But nobody follows this criteria. See the spec issue below: // https://github.com/whatwg/url/issues/53 - // - // TODO: Add *CheckHyphens* flag. // V3: neither begin nor end with a U+002D HYPHEN-MINUS - else if label.starts_with("-") || label.ends_with("-") { + else if config.check_hyphens && (label.starts_with("-") || label.ends_with("-")) { errors.push(Error::ValidityCriteria); } @@ -356,12 +354,13 @@ fn processing(domain: &str, config: Config, errors: &mut Vec) -> String { #[derive(Clone, Copy)] pub struct Config { flags: Flags, + check_hyphens: bool, } impl From for Config { #[inline] fn from(flags: Flags) -> Self { - Self { flags } + Self { flags, check_hyphens: false } } } @@ -384,6 +383,12 @@ impl Config { self } + #[inline] + pub fn check_hyphens(mut self, value: bool) -> Self { + self.check_hyphens = value; + self + } + /// http://www.unicode.org/reports/tr46/#ToASCII pub fn to_ascii(self, domain: &str) -> Result { let mut errors = Vec::new();