Subject: Re: bug#63644: 29.0.91; Coding system detection defect in html

From: Eli Zaretskii <[email-masked]>
Date: Mon, 22 May 2023 19:04:02 +0300

> From: Ikumi Keita <[email-masked]>
> Date: Mon, 22 May 2023 22:59:23 +0900
> 
> 0. Save the following file as /tmp/foo.html with the coding system `euc-jp':
> ----------------------------------------------------------------------
> <!DOCTYPE html>
> <html lang="ja">
> <head>
> <meta charset="EUC-JP">
> <title>dummy</title>
> </head>
> <body>
> あいうえお
> </body></html>
> ----------------------------------------------------------------------
> 1. emacs -Q
> 2. C-x C-f /tmp/foo.html RET
> 3. M-: (sgml-html-meta-auto-coding-function 1000) RET
> 4. Then emacs signals error with the following backtrace:
> Debugger entered--Lisp error: (coding-system-error iso-2022)
>   coding-system-plist(iso-2022)
>   coding-system-equal(utf-8 iso-2022)
>   sgml-html-meta-auto-coding-function(1000)
>   eval((sgml-html-meta-auto-coding-function 1000) t)
>   eval-expression((sgml-html-meta-auto-coding-function 1000) nil nil 127)
>   funcall-interactively(eval-expression (sgml-html-meta-auto-coding-function 1000) nil nil 127)
>   call-interactively(eval-expression nil nil)
>   command-execute(eval-expression)

Thanks.  Does the patch below give good results?

diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index 25b90b4..2b44a2e 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -2484,10 +2484,12 @@ sgml-xml-auto-coding-function
                     ;; called as part of visiting a file, as opposed
                     ;; to when saving a buffer to a file.
                     (if (and enable-multibyte-characters
-                             ;; 'charset' will signal an error in
-                             ;; coding-system-equal, since it isn't a
-                             ;; coding-system.  So test that up front.
+                             ;; 'charset' and 'iso-2022' will signal
+                             ;; an error in coding-system-equal, since
+                             ;; they aren't coding-systems.  So test
+                             ;; that up front.
                              (not (equal sym-type 'charset))
+                             (not (equal sym-type 'iso-2022))
                              (coding-system-equal 'utf-8 sym-type)
                              (coding-system-equal 'utf-8 bfcs-type))
                         buffer-file-coding-system
@@ -2540,11 +2542,13 @@ sgml-html-meta-auto-coding-function
                   (bfcs-type
                    (coding-system-type buffer-file-coding-system)))
               (if (and enable-multibyte-characters
-                       ;; 'charset' will signal an error in
-                       ;; coding-system-equal, since it isn't a
-                       ;; coding-system.  So test that up front.
+                       ;; 'charset' and 'iso-2022' will signal an error
+                       ;; in coding-system-equal, since they aren't
+                       ;; coding-systems.  So test that up front.
                        (not (equal sym-type 'charset))
                        (not (equal bfcs-type 'charset))
+                       (not (equal sym-type 'iso-2022))
+                       (not (equal bfcs-type 'iso-2022))
                        (coding-system-equal 'utf-8 sym-type)
                        (coding-system-equal 'utf-8 bfcs-type))
                   buffer-file-coding-system