LibUnicode: Support IgnorePunnycode option in ToAscii algorithm

This was introduced in UTS 46 revision 31.
This commit is contained in:
Shannon Booth 2024-12-01 22:54:06 +13:00 committed by Alexander Kalenik
parent 5dfb825c5c
commit 923ab8658e
Notes: github-actions[bot] 2024-12-05 16:30:43 +00:00
2 changed files with 11 additions and 0 deletions

View file

@ -45,12 +45,17 @@ ErrorOr<String> to_ascii(Utf8View domain_name, ToAsciiOptions const& options)
errors &= ~UIDNA_ERROR_LEADING_HYPHEN;
errors &= ~UIDNA_ERROR_TRAILING_HYPHEN;
}
if (options.verify_dns_length == VerifyDnsLength::No) {
errors &= ~UIDNA_ERROR_EMPTY_LABEL;
errors &= ~UIDNA_ERROR_LABEL_TOO_LONG;
errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG;
}
if (options.ignore_invalid_punycode == IgnoreInvalidPunycode::Yes) {
errors &= ~UIDNA_ERROR_PUNYCODE;
}
if (icu_failure(status) || errors != 0)
return Error::from_string_literal("Unable to convert domain to ASCII");

View file

@ -42,6 +42,11 @@ enum class VerifyDnsLength {
Yes,
};
enum class IgnoreInvalidPunycode {
No,
Yes,
};
struct ToAsciiOptions {
CheckHyphens check_hyphens { CheckHyphens::Yes };
CheckBidi check_bidi { CheckBidi::Yes };
@ -49,6 +54,7 @@ struct ToAsciiOptions {
UseStd3AsciiRules use_std3_ascii_rules { UseStd3AsciiRules::No };
TransitionalProcessing transitional_processing { TransitionalProcessing::No };
VerifyDnsLength verify_dns_length { VerifyDnsLength::Yes };
IgnoreInvalidPunycode ignore_invalid_punycode { IgnoreInvalidPunycode::No };
};
ErrorOr<String> to_ascii(Utf8View domain_name, ToAsciiOptions const& = {});