Skip to content

Commit 6e18952

Browse files
committed
Introduce Config::check_hyphens in uts46
Hyphens are checked by default.
1 parent 946c298 commit 6e18952

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

idna/src/uts46.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,9 @@ fn validate(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec<
253253
// NOTE: Spec says that the label must not contain a HYPHEN-MINUS character in both the
254254
// third and fourth positions. But nobody follows this criteria. See the spec issue below:
255255
// https://github.com/whatwg/url/issues/53
256-
//
257-
// TODO: Add *CheckHyphens* flag.
258256

259257
// V3: neither begin nor end with a U+002D HYPHEN-MINUS
260-
else if label.starts_with("-") || label.ends_with("-") {
258+
else if config.check_hyphens && (label.starts_with("-") || label.ends_with("-")) {
261259
errors.push(Error::ValidityCriteria);
262260
}
263261

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

361360
impl From<Flags> for Config {
362361
#[inline]
363362
fn from(flags: Flags) -> Self {
364-
Self { flags }
363+
Self { flags, check_hyphens: true }
365364
}
366365
}
367366

@@ -384,6 +383,12 @@ impl Config {
384383
self
385384
}
386385

386+
#[inline]
387+
pub fn check_hyphens(mut self, value: bool) -> Self {
388+
self.check_hyphens = value;
389+
self
390+
}
391+
387392
/// http://www.unicode.org/reports/tr46/#ToASCII
388393
pub fn to_ascii(self, domain: &str) -> Result<String, Errors> {
389394
let mut errors = Vec::new();

0 commit comments

Comments
 (0)