diff --git a/intl/components/src/IDNA.h b/intl/components/src/IDNA.h index f7af2f245422..9f186614032f 100644 --- a/intl/components/src/IDNA.h +++ b/intl/components/src/IDNA.h @@ -65,6 +65,15 @@ class IDNA final { return (mErrorCode & UIDNA_ERROR_PUNYCODE) != 0; } + /* The label was successfully ACE (Punycode) decoded but the resulting + * string had severe validation errors. For example, + * it might contain characters that are not allowed in ACE labels, + * or it might not be normalized. + */ + bool HasInvalidAceLabel() const { + return (mErrorCode & UIDNA_ERROR_INVALID_ACE_LABEL) != 0; + } + /** * Checks if the domain name label has any invalid hyphen characters. * diff --git a/netwerk/dns/nsIDNService.cpp b/netwerk/dns/nsIDNService.cpp index 9ec981eaf173..52401cbc78a3 100644 --- a/netwerk/dns/nsIDNService.cpp +++ b/netwerk/dns/nsIDNService.cpp @@ -188,8 +188,8 @@ nsresult nsIDNService::IDNA2008StringPrep(const nsAString& input, // appears to get an appended U+FFFD REPLACEMENT CHARACTER, which will // confuse our subsequent processing, so we drop that. // (https://bugzilla.mozilla.org/show_bug.cgi?id=1399540#c9) - if (info.HasInvalidPunycode() && !output.IsEmpty() && - output.Last() == 0xfffd) { + if ((info.HasInvalidPunycode() || info.HasInvalidAceLabel()) && + !output.IsEmpty() && output.Last() == 0xfffd) { output.Truncate(output.Length() - 1); } diff --git a/netwerk/test/unit/test_URIs.js b/netwerk/test/unit/test_URIs.js index 09484b43270c..622f7199db6e 100644 --- a/netwerk/test/unit/test_URIs.js +++ b/netwerk/test/unit/test_URIs.js @@ -1036,3 +1036,8 @@ add_task(function test_iconURI_serialization() { add_task(function test_jarURI_serialization() { check_round_trip_serialization("jar:http://example.com/bar.jar!/"); }); + +add_task(async function round_trip_invalid_ace_label() { + let uri = Services.io.newURI("http://xn--xn--d--fg4n-5y45d/"); + Assert.equal(uri.spec, "http://xn--xn--d--fg4n-5y45d/"); +});