GNU bug report logs - #23688
25.1.50; Incorrect punycode decoding for names without ASCII characters

Previous Next

Package: emacs;

Reported by: Magnus Henoch <magnus.henoch <at> gmail.com>

Date: Fri, 3 Jun 2016 08:46:02 UTC

Severity: normal

Tags: patch

Found in version 25.1.50

Fixed in version 26.1

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #10 received at 23688-done <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: 23688-done <at> debbugs.gnu.org
Subject: Re: bug#23688: 25.1.50;
 Incorrect punycode decoding for names without ASCII characters
Date: Wed, 01 Mar 2017 20:39:17 -0500
Version: 26.1

Magnus Henoch wrote:

> When decoding an IDN label that doesn't contain any ASCII characters,
> the function puny-decode-string-internal would skip the first letter,
> thereby returning gibberish instead of the expected result.
>
> That is, the example in the puny-decode-string docstring,
> "xn--bcher-kva", would be decoded correctly since it finds the "kva"
> part after the last dash, but my domain "xn--9dbdkw.se" would not,
> since there is no "last dash".
>
> This patch seems to fix the problem:

Thanks. That patch did not seem quite right (eg try it on "xn--bcher-kva"),
so I applied the following, which works for me.

commit 8c1e16b
Date:   Wed Mar 1 20:35:41 2017 -0500

    Small puny.el fix
    
    * lisp/net/puny.el (puny-decode-string-internal):
    Handle strings with no ascii parts.  (Bug#23688)

diff --git a/lisp/net/puny.el b/lisp/net/puny.el
index c718d95..bdd59be 100644
--- a/lisp/net/puny.el
+++ b/lisp/net/puny.el
@@ -150,10 +150,12 @@ For instance \"xn--bcher-kva\" => \"bücher\"."
 (defun puny-decode-string-internal (string)
   (with-temp-buffer
     (insert string)
-    (goto-char (point-max))
-    (search-backward "-" nil (point-min))
-    ;; The encoded chars are after the final dash.
-    (let ((encoded (buffer-substring (1+ (point)) (point-max)))
+    ;; The encoded chars are after any final dash, else the whole string.
+    (let ((encoded (buffer-substring
+                    (if (search-backward "-" nil 'move)
+                        (1+ (point))
+                      (point))
+                    (point-max)))
           (ic 0)
           (i 0)
           (bias puny-initial-bias)




This bug report was last modified 8 years and 79 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.