Skip to content

Commit 4fcb9da

Browse files
shannonboothpbrw
authored andcommitted
LibUnicode: Support IgnorePunnycode option in ToAscii algorithm
This was introduced in UTS 46 revision 31.
1 parent 493b485 commit 4fcb9da

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Libraries/LibUnicode/IDNA.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ ErrorOr<String> to_ascii(Utf8View domain_name, ToAsciiOptions const& options)
4545
errors &= ~UIDNA_ERROR_LEADING_HYPHEN;
4646
errors &= ~UIDNA_ERROR_TRAILING_HYPHEN;
4747
}
48+
4849
if (options.verify_dns_length == VerifyDnsLength::No) {
4950
errors &= ~UIDNA_ERROR_EMPTY_LABEL;
5051
errors &= ~UIDNA_ERROR_LABEL_TOO_LONG;
5152
errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG;
5253
}
5354

55+
if (options.ignore_invalid_punycode == IgnoreInvalidPunycode::Yes) {
56+
errors &= ~UIDNA_ERROR_PUNYCODE;
57+
}
58+
5459
if (icu_failure(status) || errors != 0)
5560
return Error::from_string_literal("Unable to convert domain to ASCII");
5661

Libraries/LibUnicode/IDNA.h

+6
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ enum class VerifyDnsLength {
4242
Yes,
4343
};
4444

45+
enum class IgnoreInvalidPunycode {
46+
No,
47+
Yes,
48+
};
49+
4550
struct ToAsciiOptions {
4651
CheckHyphens check_hyphens { CheckHyphens::Yes };
4752
CheckBidi check_bidi { CheckBidi::Yes };
4853
CheckJoiners check_joiners { CheckJoiners::Yes };
4954
UseStd3AsciiRules use_std3_ascii_rules { UseStd3AsciiRules::No };
5055
TransitionalProcessing transitional_processing { TransitionalProcessing::No };
5156
VerifyDnsLength verify_dns_length { VerifyDnsLength::Yes };
57+
IgnoreInvalidPunycode ignore_invalid_punycode { IgnoreInvalidPunycode::No };
5258
};
5359

5460
ErrorOr<String> to_ascii(Utf8View domain_name, ToAsciiOptions const& = {});

0 commit comments

Comments
 (0)