Skip to content

Commit

Permalink
Introduce Config::check_hyphens in uts46
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Feb 11, 2019
1 parent 946c298 commit 065ece2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions idna/src/uts46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -356,12 +354,13 @@ fn processing(domain: &str, config: Config, errors: &mut Vec<Error>) -> String {
#[derive(Clone, Copy)]
pub struct Config {
flags: Flags,
check_hyphens: bool,
}

impl From<Flags> for Config {
#[inline]
fn from(flags: Flags) -> Self {
Self { flags }
Self { flags, check_hyphens: false }
}
}

Expand All @@ -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<String, Errors> {
let mut errors = Vec::new();
Expand Down

0 comments on commit 065ece2

Please sign in to comment.