]> 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)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Dec 2020 17:08:31 +0000 (18:08 +0100)
This follows more closely what web browsers do, and makes sure emojis in
domains work.

Fixes: #14483
(cherry picked from commit d80e72ec602c2af2983842ad87e4443fce89d423)

src/shared/dns-domain.c

index b812665315f63dc0dc872dc03660a1508c969743..8912194352901b81658d41cc661ed4e9a8e9d512 100644 (file)
@@ -1274,8 +1274,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 = 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 = 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--")) {