Skip to content

Commit 946c298

Browse files
committed
Pass a Config value to validate in uts46
1 parent 667c896 commit 946c298

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

idna/src/uts46.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,16 @@ fn passes_bidi(label: &str, is_bidi_domain: bool) -> bool {
233233
}
234234

235235
/// http://www.unicode.org/reports/tr46/#Validity_Criteria
236-
fn validate_full(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Error>) {
236+
fn validate_full(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec<Error>) {
237237
// V1: Must be in NFC form.
238238
if label.nfc().ne(label.chars()) {
239239
errors.push(Error::ValidityCriteria);
240240
} else {
241-
validate(label, is_bidi_domain, flags, errors);
241+
validate(label, is_bidi_domain, config, errors);
242242
}
243243
}
244244

245-
fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Error>) {
245+
fn validate(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec<Error>) {
246246
let first_char = label.chars().next();
247247
if first_char == None {
248248
// Empty string, pass
@@ -273,8 +273,8 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
273273
// V6: Check against Mapping Table
274274
else if label.chars().any(|c| match *find_char(c) {
275275
Mapping::Valid => false,
276-
Mapping::Deviation(_) => flags.transitional_processing,
277-
Mapping::DisallowedStd3Valid => flags.use_std3_ascii_rules,
276+
Mapping::Deviation(_) => config.flags.transitional_processing,
277+
Mapping::DisallowedStd3Valid => config.flags.use_std3_ascii_rules,
278278
_ => true,
279279
}) {
280280
errors.push(Error::ValidityCriteria);
@@ -294,10 +294,10 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
294294
}
295295

296296
/// http://www.unicode.org/reports/tr46/#Processing
297-
fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
297+
fn processing(domain: &str, config: Config, errors: &mut Vec<Error>) -> String {
298298
let mut mapped = String::with_capacity(domain.len());
299299
for c in domain.chars() {
300-
map_char(c, flags, &mut mapped, errors)
300+
map_char(c, config.flags, &mut mapped, errors)
301301
}
302302
let mut normalized = String::with_capacity(mapped.len());
303303
normalized.extend(mapped.nfc());
@@ -338,15 +338,15 @@ fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
338338
if label.starts_with(PUNYCODE_PREFIX) {
339339
match punycode::decode_to_string(&label[PUNYCODE_PREFIX.len()..]) {
340340
Some(decoded_label) => {
341-
let flags = Flags { transitional_processing: false, ..flags };
342-
validate_full(&decoded_label, is_bidi_domain, flags, errors);
341+
let config = config.transitional_processing(false);
342+
validate_full(&decoded_label, is_bidi_domain, config, errors);
343343
validated.push_str(&decoded_label)
344344
}
345345
None => errors.push(Error::PunycodeError)
346346
}
347347
} else {
348348
// `normalized` is already `NFC` so we can skip that check
349-
validate(label, is_bidi_domain, flags, errors);
349+
validate(label, is_bidi_domain, config, errors);
350350
validated.push_str(label)
351351
}
352352
}
@@ -389,7 +389,7 @@ impl Config {
389389
let mut errors = Vec::new();
390390
let mut result = String::new();
391391
let mut first = true;
392-
for label in processing(domain, self.flags, &mut errors).split('.') {
392+
for label in processing(domain, self, &mut errors).split('.') {
393393
if !first {
394394
result.push('.');
395395
}
@@ -426,7 +426,7 @@ impl Config {
426426
/// http://www.unicode.org/reports/tr46/#ToUnicode
427427
pub fn to_unicode(self, domain: &str) -> (String, Result<(), Errors>) {
428428
let mut errors = Vec::new();
429-
let domain = processing(domain, self.flags, &mut errors);
429+
let domain = processing(domain, self, &mut errors);
430430
let errors = if errors.is_empty() {
431431
Ok(())
432432
} else {

0 commit comments

Comments
 (0)