summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaijiro Wachi <daijiro.wachi@gmail.com>2017-05-01 17:26:21 +0200
committerDaijiro Wachi <daijiro.wachi@gmail.com>2017-05-01 17:26:21 +0200
commit0f58d3cbefbe744a8e5f9383c08eefc2991b8d1c (patch)
tree21cf9cfa0b48ffc20e45f09b9e1fe822a53c5b4a /src
parent6ed791c665de2c1838f6080a1b377b0008cf535b (diff)
downloadandroid-node-v8-0f58d3cbefbe744a8e5f9383c08eefc2991b8d1c.tar.gz
android-node-v8-0f58d3cbefbe744a8e5f9383c08eefc2991b8d1c.tar.bz2
android-node-v8-0f58d3cbefbe744a8e5f9383c08eefc2991b8d1c.zip
src: support domains with empty labels
Follow the spec of domainToASCII/domainToUnicode in whatwg, and synchronise WPT url test data. Refs: https://github.com/w3c/web-platform-tests/pull/5397 PR-URL: https://github.com/nodejs/node/pull/12707 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_i18n.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc
index 13fb77b15d..6d966bb117 100644
--- a/src/node_i18n.cc
+++ b/src/node_i18n.cc
@@ -461,6 +461,13 @@ int32_t ToUnicode(MaybeStackBuffer<char>* buf,
&status);
}
+ // UTS #46's ToUnicode operation applies no validation of domain name length
+ // (nor a flag requesting it to do so, like VerifyDnsLength for ToASCII). For
+ // that reason, unlike ToASCII below, ICU4C correctly accepts long domain
+ // names. However, ICU4C still sets the EMPTY_LABEL error in contrary to UTS
+ // #46. Therefore, explicitly filters out that error here.
+ info.errors &= ~UIDNA_ERROR_EMPTY_LABEL;
+
if (U_FAILURE(status) || (!lenient && info.errors != 0)) {
len = -1;
buf->SetLength(0);
@@ -500,6 +507,16 @@ int32_t ToASCII(MaybeStackBuffer<char>* buf,
&status);
}
+ // The WHATWG URL "domain to ASCII" algorithm explicitly sets the
+ // VerifyDnsLength flag to false, which disables the domain name length
+ // verification step in ToASCII (as specified by UTS #46). Unfortunately,
+ // ICU4C's IDNA module does not support disabling this flag through `options`,
+ // so just filter out the errors that may be caused by the verification step
+ // afterwards.
+ info.errors &= ~UIDNA_ERROR_EMPTY_LABEL;
+ info.errors &= ~UIDNA_ERROR_LABEL_TOO_LONG;
+ info.errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG;
+
if (U_FAILURE(status) || (!lenient && info.errors != 0)) {
len = -1;
buf->SetLength(0);