@@ -220,17 +220,21 @@ fn passes_bidi(label: &str, is_bidi_domain: bool) -> bool {
220
220
}
221
221
222
222
/// http://www.unicode.org/reports/tr46/#Validity_Criteria
223
+ fn validate_full ( label : & str , is_bidi_domain : bool , flags : Flags , errors : & mut Vec < Error > ) {
224
+ // V1: Must be in NFC form.
225
+ if label. nfc ( ) . ne ( label. chars ( ) ) {
226
+ errors. push ( Error :: ValidityCriteria ) ;
227
+ } else {
228
+ validate ( label, is_bidi_domain, flags, errors) ;
229
+ }
230
+ }
231
+
223
232
fn validate ( label : & str , is_bidi_domain : bool , flags : Flags , errors : & mut Vec < Error > ) {
224
233
let first_char = label. chars ( ) . next ( ) ;
225
234
if first_char == None {
226
235
// Empty string, pass
227
236
}
228
237
229
- // V1: Must be in NFC form.
230
- else if label. nfc ( ) . ne ( label. chars ( ) ) {
231
- errors. push ( Error :: ValidityCriteria ) ;
232
- }
233
-
234
238
// V2: No U+002D HYPHEN-MINUS in both third and fourth positions.
235
239
//
236
240
// NOTE: Spec says that the label must not contain a HYPHEN-MINUS character in both the
@@ -322,12 +326,13 @@ fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
322
326
match punycode:: decode_to_string ( & label[ PUNYCODE_PREFIX . len ( ) ..] ) {
323
327
Some ( decoded_label) => {
324
328
let flags = Flags { transitional_processing : false , ..flags } ;
325
- validate ( & decoded_label, is_bidi_domain, flags, errors) ;
329
+ validate_full ( & decoded_label, is_bidi_domain, flags, errors) ;
326
330
validated. push_str ( & decoded_label)
327
331
}
328
332
None => errors. push ( Error :: PunycodeError )
329
333
}
330
334
} else {
335
+ // `normalized` is already `NFC` so we can skip that check
331
336
validate ( label, is_bidi_domain, flags, errors) ;
332
337
validated. push_str ( label)
333
338
}
0 commit comments