diff --git a/src/psl.c b/src/psl.c index 14a2035..f3b2156 100644 --- a/src/psl.c +++ b/src/psl.c @@ -701,6 +701,17 @@ static int _psl_idna_toASCII(_psl_idna_t *idna _UNUSED, const char *utf8, char * fprintf(stderr, "Failed to convert UTF-8 to UTF-16 (status %d)\n", status); */ } #elif defined(WITH_LIBIDN2) +#if IDN2_VERSION_NUMBER >= 0x00140000 + int rc; + + /* IDN2_TRANSITIONAL automatically converts to lowercase */ + /* IDN2_NFC_INPUT converts to NFC before toASCII conversion */ + + if ((rc = idn2_lookup_u8((uint8_t *)utf8, (uint8_t **)ascii, IDN2_NFC_INPUT | IDN2_TRANSITIONAL)) == IDN2_OK) + ret = 0; + /* else + fprintf(stderr, "toASCII(%s) failed (%d): %s\n", lower, rc, idn2_strerror(rc)); */ +#else int rc; uint8_t *lower; size_t len = u8_strlen((uint8_t *)utf8) + 1; @@ -717,6 +728,7 @@ static int _psl_idna_toASCII(_psl_idna_t *idna _UNUSED, const char *utf8, char * fprintf(stderr, "toASCII(%s) failed (%d): %s\n", lower, rc, idn2_strerror(rc)); */ free(lower); +#endif #elif defined(WITH_LIBIDN) int rc;