Skip to content

Commit

Permalink
Verify Unicode ToASCII result is not the empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed May 6, 2020
1 parent dbe25bd commit 807bf50
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/url_idna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const UIDNA* getUIDNA() {
// version with StringByteSink. That way, we can avoid C wrappers and additional
// string conversion.

// https://url.spec.whatwg.org/#concept-domain-to-ascii
// with beStrict = false

static_assert(sizeof(char16_t) == sizeof(UChar), "");

url_result IDNToASCII(const char16_t* src, std::size_t src_len, simple_buffer<char16_t>& output) {
Expand Down Expand Up @@ -94,6 +97,11 @@ url_result IDNToASCII(const char16_t* src, std::size_t src_len, simple_buffer<ch
&info, &err);
if (U_SUCCESS(err) && (info.errors & UIDNA_ERR_MASK) == 0) {
output.resize(output_length);
// Result of uidna_nameToASCII can be the empty string if input:
// 1) consists entirely of IDNA ignored code points;
// 2) is "xn--".
if (output_length == 0)
return url_result::EmptyHost;
return url_result::Ok;
}

Expand Down

0 comments on commit 807bf50

Please sign in to comment.