GNU bug report logs - #54195
27.1; electric-pair-mode assertion failure in HTML+JS mode

Previous Next

Package: emacs;

Reported by: Jeff Chase <jeff.chase <at> gmail.com>

Date: Mon, 28 Feb 2022 08:16:07 UTC

Severity: normal

Found in version 27.1

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 54195 in the body.
You can then email your comments to 54195 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#54195; Package emacs. (Mon, 28 Feb 2022 08:16:07 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jeff Chase <jeff.chase <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 28 Feb 2022 08:16:07 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jeff Chase <jeff.chase <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.1; electric-pair-mode assertion failure in HTML+JS mode
Date: Sun, 27 Feb 2022 22:29:58 -0500
[Message part 1 (text/plain, inline)]
1) open a new file named 'test.html'
2) enable electric-pair-mode
3) Add

    <script>

    </script>

4) When mark is between script tags should be in HTML+JS mode
5) Enter `foo()` on the line between script tags

The closing paren should overwrite the auto closing paren but instead
a new one is added and the minibuffer shows an error:

    Assertion failed: (>= (cadr sgml--syntax-propertize-ppss) 0)

This does not happen under the other major modes I tried nor in HTML+
mode outside of the script tags.


In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu)
 of 2021-03-27, modified by Debian built on x86-conova-01
System Description: Debian GNU/Linux 11 (bullseye)

Recent messages:
next-line: End of buffer
(New file)
Type C-x 1 to delete the help window, C-M-v to scroll help.
Saving file /tmp/test...
Wrote /tmp/test
kill-line: End of buffer
Auto-saving...done
cl--assertion-failed: Assertion failed: (>= (cadr
sgml--syntax-propertize-ppss) 0)
Auto-saving...


Configured using:
 'configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --enable-libsystemd --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-mailutils --build
 x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd
 --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-mailutils --with-x=no
 --without-gsettings 'CFLAGS=-g -O2
 -ffile-prefix-map=/build/emacs-LlFm6W/emacs-27.1+1=.
-fstack-protector-strong
 -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
 -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro'

Configured features:
SOUND GPM DBUS NOTIFY INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 ZLIB XIM
MODULES THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: HTML+JS

Minor modes in effect:
  electric-pair-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc dired dired-loaddefs rfc822
mml mml-sec epa derived epg epg-config mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail cl-extra
help-fns radix-tree help-mode cus-start cus-load elec-pair mhtml-mode
css-mode smie eww mm-url gnus nnheader gnus-util rmail rmail-loaddefs
rfc2047 rfc2045 ietf-drums time-date mail-utils wid-edit mm-util
mail-prsvr thingatpt url-queue url url-proxy url-privacy url-expand
url-methods url-history mailcap shr text-property-search url-cookie
url-domsuf url-util puny image svg xml format-spec color js imenu
cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs sgml-mode dom term/xterm xterm regexp-opt finder-inf
info tool-bar package easymenu browse-url url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json subr-x map url-vars seq byte-opt gv bytecomp
byte-compile cconv cl-loaddefs cl-lib tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch timer select mouse jit-lock font-lock syntax
facemenu font-core term/tty-colors frame minibuffer cl-generic cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 281157 11962)
 (symbols 48 20226 1)
 (strings 32 93300 2645)
 (string-bytes 1 2493314)
 (vectors 16 24683)
 (vector-slots 8 311705 10980)
 (floats 8 233 302)
 (intervals 56 570 0)
 (buffers 1000 17))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54195; Package emacs. (Mon, 28 Feb 2022 09:31:02 GMT) Full text and rfc822 format available.

Message #8 received at 54195 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Jeff Chase <jeff.chase <at> gmail.com>
Cc: 54195 <at> debbugs.gnu.org
Subject: Re: bug#54195: 27.1; electric-pair-mode assertion failure in
 HTML+JS mode
Date: Mon, 28 Feb 2022 10:30:42 +0100
Jeff Chase <jeff.chase <at> gmail.com> writes:

> 1) open a new file named 'test.html'
> 2) enable electric-pair-mode
> 3) Add
>
>     <script>
>
>     </script>
>
> 4) When mark is between script tags should be in HTML+JS mode
> 5) Enter `foo()` on the line between script tags
>
> The closing paren should overwrite the auto closing paren but instead
> a new one is added and the minibuffer shows an error:
>
>     Assertion failed: (>= (cadr sgml--syntax-propertize-ppss) 0)
>
> This does not happen under the other major modes I tried nor in HTML+
> mode outside of the script tags.

I've now fixed this in Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 29.1, send any further explanations to 54195 <at> debbugs.gnu.org and Jeff Chase <jeff.chase <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 28 Feb 2022 09:32:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54195; Package emacs. (Mon, 28 Feb 2022 14:45:02 GMT) Full text and rfc822 format available.

Message #13 received at 54195 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 54195 <at> debbugs.gnu.org
Subject: Re: master 15a76160bb: Don't throw errors while propertizing in
 sgml-mode
Date: Mon, 28 Feb 2022 09:44:01 -0500
>     * lisp/textmodes/sgml-mode.el (sgml-syntax-propertize): Don't
>     throw an error when propertizing (bug#54195).
> ---
>  lisp/textmodes/sgml-mode.el | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
> index 83631e6475..b49541f47d 100644
> --- a/lisp/textmodes/sgml-mode.el
> +++ b/lisp/textmodes/sgml-mode.el
> @@ -419,11 +419,11 @@ These have to be run via `sgml-syntax-propertize'"))
>  (defun sgml-syntax-propertize (start end &optional rules-function)
>    "Syntactic keywords for `sgml-mode'."
>    (setq sgml--syntax-propertize-ppss (cons start (syntax-ppss start)))
> -  (cl-assert (>= (cadr sgml--syntax-propertize-ppss) 0))
> -  (sgml-syntax-propertize-inside end)
> -  (funcall (or rules-function sgml--syntax-propertize) (point) end)
> -  ;; Catch any '>' after the last quote.
> -  (sgml--syntax-propertize-ppss end))
> +  (when (>= (cadr sgml--syntax-propertize-ppss) 0)
> +    (sgml-syntax-propertize-inside end)
> +    (funcall (or rules-function sgml--syntax-propertize) (point) end)
> +    ;; Catch any '>' after the last quote.
> +    (sgml--syntax-propertize-ppss end)))

Hmm... this isn't right.

The PPSS really shouldn't have a negative value here.  The problem is
that when we do as in the recipe (which does not require
`electric-pair-mode` to reproduce), mhtml calls `sgml-syntax-propertize`
on the `</script>` tag and the `syntax-ppss` call returns the state of
the JS parsing at the end of the JS code rather than the state of the
SGML parsing at the beginning of the tag.

IOW it's a bug in the interaction between `mhtml` and `syntax-ppss`.

To illustrate the problem in a way which doesn't signal an error, try
the following:

    "foo
    <script>
      foo()
    </script>
    "bar
    <foo "hello">

as you can see, the SGML part carefully ignores the " thingies outside
of quotes.  Now remove the closing paren in the JS code: suddenly the
SGML code is all confused because it thinks everything after the open
paren is inside of a tag (because the SGML mode gives paren syntax to <
and > (but not to parens) and uses the paren depth to decide whether
we're inside a tag or not).


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54195; Package emacs. (Tue, 01 Mar 2022 15:16:01 GMT) Full text and rfc822 format available.

Message #16 received at 54195 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 54195 <at> debbugs.gnu.org
Subject: Re: master 15a76160bb: Don't throw errors while propertizing in
 sgml-mode
Date: Tue, 01 Mar 2022 16:15:38 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> The PPSS really shouldn't have a negative value here.  The problem is
> that when we do as in the recipe (which does not require
> `electric-pair-mode` to reproduce), mhtml calls `sgml-syntax-propertize`
> on the `</script>` tag and the `syntax-ppss` call returns the state of
> the JS parsing at the end of the JS code rather than the state of the
> SGML parsing at the beginning of the tag.
>
> IOW it's a bug in the interaction between `mhtml` and `syntax-ppss`.

I assumed that people didn't normally get any erroring-out here because
these functions are normally called from font-locking, which catches
most errors.  When electric-pair-mode is used, the syntax functions are
called via a different code path that doesn't catch errors, so I thought
it'd make most sense to not call `error' from the code at all.

But yes, the parsing won't be correct.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 30 Mar 2022 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 141 days ago.

Previous Next


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