|
@@ -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
|
|
// 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:
|
|
// third and fourth positions. But nobody follows this criteria. See the spec issue below:
|
|
|
// https://github.com/whatwg/url/issues/53
|
|
// https://github.com/whatwg/url/issues/53
|
|
|
- //
|
|
|
|
|
- // TODO: Add *CheckHyphens* flag.
|
|
|
|
|
|
|
|
|
|
// V3: neither begin nor end with a U+002D HYPHEN-MINUS
|
|
// 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);
|
|
errors.push(Error::ValidityCriteria);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -356,12 +354,13 @@ fn processing(domain: &str, config: Config, errors: &mut Vec<Error>) -> String {
|
|
|
#[derive(Clone, Copy)]
|
|
#[derive(Clone, Copy)]
|
|
|
pub struct Config {
|
|
pub struct Config {
|
|
|
flags: Flags,
|
|
flags: Flags,
|
|
|
|
|
+ check_hyphens: bool,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl From<Flags> for Config {
|
|
impl From<Flags> for Config {
|
|
|
#[inline]
|
|
#[inline]
|
|
|
fn from(flags: Flags) -> Self {
|
|
fn from(flags: Flags) -> Self {
|
|
|
- Self { flags }
|
|
|
|
|
|
|
+ Self { flags, check_hyphens: true }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -384,6 +383,12 @@ impl Config {
|
|
|
self
|
|
self
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ #[inline]
|
|
|
|
|
+ pub fn check_hyphens(mut self, value: bool) -> Self {
|
|
|
|
|
+ self.check_hyphens = value;
|
|
|
|
|
+ self
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// http://www.unicode.org/reports/tr46/#ToASCII
|
|
/// http://www.unicode.org/reports/tr46/#ToASCII
|
|
|
pub fn to_ascii(self, domain: &str) -> Result<String, Errors> {
|
|
pub fn to_ascii(self, domain: &str) -> Result<String, Errors> {
|
|
|
let mut errors = Vec::new();
|
|
let mut errors = Vec::new();
|