aboutsummaryrefslogtreecommitdiffstats
path: root/util-src
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-09-11 00:14:59 +0200
committerKim Alvefur <zash@zash.se>2019-09-11 00:14:59 +0200
commitbb4cb60fb8200e5fa26eaa482422fbbfa71aa11c (patch)
tree817bcd094343e3710a72fb826f595f686e29679b /util-src
parentb733d61de629dabbc1678781711b3775b7ce17cd (diff)
downloadprosody-bb4cb60fb8200e5fa26eaa482422fbbfa71aa11c.tar.gz
prosody-bb4cb60fb8200e5fa26eaa482422fbbfa71aa11c.zip
util.encodings: Switch ICU binding to IDNA2008 (fixes #533, #1301)
Diffstat (limited to 'util-src')
-rw-r--r--util-src/encodings.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/util-src/encodings.c b/util-src/encodings.c
index 5e7032cf..f20ba75d 100644
--- a/util-src/encodings.c
+++ b/util-src/encodings.c
@@ -269,6 +269,7 @@ static const luaL_Reg Reg_utf8[] = {
#include <unicode/ustring.h>
#include <unicode/utrace.h>
#include <unicode/uspoof.h>
+#include <unicode/uidna.h>
static int icu_stringprep_prep(lua_State *L, const UStringPrepProfile *profile) {
size_t input_len;
@@ -323,6 +324,7 @@ UStringPrepProfile *icu_nodeprep;
UStringPrepProfile *icu_resourceprep;
UStringPrepProfile *icu_saslprep;
USpoofChecker *icu_spoofcheck;
+UIDNA *icu_idna2008;
#if (U_ICU_VERSION_MAJOR_NUM < 58)
/* COMPAT */
@@ -339,6 +341,7 @@ void init_icu(void) {
icu_saslprep = usprep_openByType(USPREP_RFC4013_SASLPREP, &err);
icu_spoofcheck = uspoof_open(&err);
uspoof_setChecks(icu_spoofcheck, USPOOF_CONFUSABLE, &err);
+ icu_idna2008 = uidna_openUTS46(UIDNA_USE_STD3_RULES, &err);
if(U_FAILURE(err)) {
fprintf(stderr, "[c] util.encodings: error: %s\n", u_errorName((UErrorCode)err));
@@ -434,9 +437,10 @@ static int Lidna_to_ascii(lua_State *L) { /** idna.to_ascii(s) */
return 1;
}
- dest_len = uidna_IDNToASCII(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err);
+ UIDNAInfo info = UIDNA_INFO_INITIALIZER;
+ dest_len = uidna_nameToASCII(icu_idna2008, ustr, ulen, dest, 256, &info, &err);
- if(U_FAILURE(err)) {
+ if(U_FAILURE(err) || info.errors) {
lua_pushnil(L);
return 1;
} else {
@@ -468,9 +472,10 @@ static int Lidna_to_unicode(lua_State *L) { /** idna.to_unicode(s) */
return 1;
}
- dest_len = uidna_IDNToUnicode(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err);
+ UIDNAInfo info = UIDNA_INFO_INITIALIZER;
+ dest_len = uidna_nameToUnicode(icu_idna2008, ustr, ulen, dest, 1024, &info, &err);
- if(U_FAILURE(err)) {
+ if(U_FAILURE(err) || info.errors) {
lua_pushnil(L);
return 1;
} else {