]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dns-domain: try IDN2003 rules if IDN2008 doesn't work
authorLennart Poettering <lennart@poettering.net>
Mon, 9 Nov 2020 22:10:43 +0000 (23:10 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Dec 2020 23:48:11 +0000 (08:48 +0900)
This follows more closely what web browsers do, and makes sure emojis in
domains work.

Fixes: #14483
src/shared/dns-domain.c

index 8bd1e3a6acd54fa931d928d7928043a4150dfc65..b02ad3f5217b76be921d011fd3bc15e20592d9d2 100644 (file)
@@ -1291,8 +1291,14 @@ int dns_name_apply_idna(const char *name, char **ret) {
         assert(name);
         assert(ret);
 
+        /* First, try non-transitional mode (i.e. IDN2008 rules) */
         r = sym_idn2_lookup_u8((uint8_t*) name, (uint8_t**) &t,
                                IDN2_NFC_INPUT | IDN2_NONTRANSITIONAL);
+        if (r == IDN2_DISALLOWED) /* If that failed, because of disallowed characters, try transitional mode.
+                                   * (i.e. IDN2003 rules which supports some unicode chars IDN2008 doesn't allow). */
+                r = sym_idn2_lookup_u8((uint8_t*) name, (uint8_t**) &t,
+                                       IDN2_NFC_INPUT | IDN2_TRANSITIONAL);
+
         log_debug("idn2_lookup_u8: %s → %s", name, t);
         if (r == IDN2_OK) {
                 if (!startswith(name, "xn--")) {