|
|
@@ -233,16 +233,16 @@ fn passes_bidi(label: &str, is_bidi_domain: bool) -> bool {
|
|
|
}
|
|
|
|
|
|
/// http://www.unicode.org/reports/tr46/#Validity_Criteria
|
|
|
-fn validate_full(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Error>) {
|
|
|
+fn validate_full(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec<Error>) {
|
|
|
// V1: Must be in NFC form.
|
|
|
if label.nfc().ne(label.chars()) {
|
|
|
errors.push(Error::ValidityCriteria);
|
|
|
} else {
|
|
|
- validate(label, is_bidi_domain, flags, errors);
|
|
|
+ validate(label, is_bidi_domain, config, errors);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Error>) {
|
|
|
+fn validate(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec<Error>) {
|
|
|
let first_char = label.chars().next();
|
|
|
if first_char == None {
|
|
|
// Empty string, pass
|
|
|
@@ -273,8 +273,8 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
|
|
|
// V6: Check against Mapping Table
|
|
|
else if label.chars().any(|c| match *find_char(c) {
|
|
|
Mapping::Valid => false,
|
|
|
- Mapping::Deviation(_) => flags.transitional_processing,
|
|
|
- Mapping::DisallowedStd3Valid => flags.use_std3_ascii_rules,
|
|
|
+ Mapping::Deviation(_) => config.flags.transitional_processing,
|
|
|
+ Mapping::DisallowedStd3Valid => config.flags.use_std3_ascii_rules,
|
|
|
_ => true,
|
|
|
}) {
|
|
|
errors.push(Error::ValidityCriteria);
|
|
|
@@ -294,10 +294,10 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
|
|
|
}
|
|
|
|
|
|
/// http://www.unicode.org/reports/tr46/#Processing
|
|
|
-fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
|
|
|
+fn processing(domain: &str, config: Config, errors: &mut Vec<Error>) -> String {
|
|
|
let mut mapped = String::with_capacity(domain.len());
|
|
|
for c in domain.chars() {
|
|
|
- map_char(c, flags, &mut mapped, errors)
|
|
|
+ map_char(c, config.flags, &mut mapped, errors)
|
|
|
}
|
|
|
let mut normalized = String::with_capacity(mapped.len());
|
|
|
normalized.extend(mapped.nfc());
|
|
|
@@ -338,15 +338,15 @@ fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
|
|
|
if label.starts_with(PUNYCODE_PREFIX) {
|
|
|
match punycode::decode_to_string(&label[PUNYCODE_PREFIX.len()..]) {
|
|
|
Some(decoded_label) => {
|
|
|
- let flags = Flags { transitional_processing: false, ..flags };
|
|
|
- validate_full(&decoded_label, is_bidi_domain, flags, errors);
|
|
|
+ let config = config.transitional_processing(false);
|
|
|
+ validate_full(&decoded_label, is_bidi_domain, config, errors);
|
|
|
validated.push_str(&decoded_label)
|
|
|
}
|
|
|
None => errors.push(Error::PunycodeError)
|
|
|
}
|
|
|
} else {
|
|
|
// `normalized` is already `NFC` so we can skip that check
|
|
|
- validate(label, is_bidi_domain, flags, errors);
|
|
|
+ validate(label, is_bidi_domain, config, errors);
|
|
|
validated.push_str(label)
|
|
|
}
|
|
|
}
|
|
|
@@ -389,7 +389,7 @@ impl Config {
|
|
|
let mut errors = Vec::new();
|
|
|
let mut result = String::new();
|
|
|
let mut first = true;
|
|
|
- for label in processing(domain, self.flags, &mut errors).split('.') {
|
|
|
+ for label in processing(domain, self, &mut errors).split('.') {
|
|
|
if !first {
|
|
|
result.push('.');
|
|
|
}
|
|
|
@@ -426,7 +426,7 @@ impl Config {
|
|
|
/// http://www.unicode.org/reports/tr46/#ToUnicode
|
|
|
pub fn to_unicode(self, domain: &str) -> (String, Result<(), Errors>) {
|
|
|
let mut errors = Vec::new();
|
|
|
- let domain = processing(domain, self.flags, &mut errors);
|
|
|
+ let domain = processing(domain, self, &mut errors);
|
|
|
let errors = if errors.is_empty() {
|
|
|
Ok(())
|
|
|
} else {
|