GNU bug report logs - #75928
31.0.50; `dom-print' often fails to print an SVG DOM

Previous Next

Package: emacs;

Reported by: David Ponce <da_vid <at> orange.fr>

Date: Wed, 29 Jan 2025 15:53:02 UTC

Severity: normal

Tags: patch

Found in version 31.0.50

Done: Eli Zaretskii <eliz <at> gnu.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 75928 in the body.
You can then email your comments to 75928 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#75928; Package emacs. (Wed, 29 Jan 2025 15:53:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to David Ponce <da_vid <at> orange.fr>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 29 Jan 2025 15:53:02 GMT) Full text and rfc822 format available.

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

From: David Ponce <da_vid <at> orange.fr>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; `dom-print' often fails to print an SVG DOM
Date: Wed, 29 Jan 2025 16:52:28 +0100
[Message part 1 (text/plain, inline)]
Hello,

Currently `dom-print' is mostly unusable to print an SVG DOM because it
fails as soon as it encounters an attribute value which is not a string.
This is unfortunate, because `dom-print' can be very useful for
examining a DOM by pretty-printing it.

Here is a simple example that illustrates the problem:

(require 'svg)
(let ((svg (svg-create 100 100)))
  (svg-rectangle svg 0 0 "100%" "100%" :fill "blue")
  (svg-text svg "A text" :x 0 :y 55 :stroke "yellow" :fill "yellow")
  (dom-print svg t t))

Which produce this backtrace when evaluated in the *scratch* buffer:

Debugger entered--Lisp error: (wrong-type-argument sequencep 100)
  replace-regexp-in-string("[&<>\"]" #f(compiled-function (c) #<bytecode 0x1119c0c6891a2a03>) 100)
  url-insert-entities-in-string(100)
  dom-print((svg ((width . 100) (height . 100) (version . "1.1") (xmlns . "http://www.w3.org/2000/svg") (xmlns:xlink . "http://www.w3.org/1999/xlink")) (rect ((width . "100%") (height . "100%") (x . 0) (y . 0) (fill . "blue"))) (text ((fill . "yellow") (stroke . "yellow") (y . 55) (x . 0)) "A text")) t t)
  (let ((svg (svg-create 100 100))) (svg-rectangle svg 0 0 "100%" "100%" :fill "blue") (svg-text svg "A text" :x 0 :y 55 :stroke "yellow" :fill "yellow") (dom-print svg t t))
  (progn (let ((svg (svg-create 100 100))) (svg-rectangle svg 0 0 "100%" "100%" :fill "blue") (svg-text svg "A text" :x 0 :y 55 :stroke "yellow" :fill "yellow") (dom-print svg t t)))
  eval((progn (let ((svg (svg-create 100 100))) (svg-rectangle svg 0 0 "100%" "100%" :fill "blue") (svg-text svg "A text" :x 0 :y 55 :stroke "yellow" :fill "yellow") (dom-print svg t t))) t)
  elisp--eval-last-sexp(t)
  #f(compiled-function () #<bytecode 0x299b97085c5ba>)()
  handler-bind-1(#f(compiled-function () #<bytecode 0x299b97085c5ba>) (error) eval-expression--debug)
  eval-last-sexp(t)
  eval-print-last-sexp(nil)
  funcall-interactively(eval-print-last-sexp nil)
  call-interactively(eval-print-last-sexp nil nil)
  command-execute(eval-print-last-sexp)
 
The cause is that `dom-print' calls the function
`url-insert-entities-in-string' to convert special characters in
attribute value assuming this value is a string, which is not always
true in an SVG DOM.

I propose the attached very simple patch that solves the issue.
Here is a possible changelog:

2025-01-29  David Ponce  <da_vid <at> orange.fr>

	* dom.el (dom-print): Ensure to pass a string to
	`url-insert-entities-in-string'.

With this patch applied the above example prints the expected result:

<svg width="100" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <rect width="100%" height="100%" x="0" y="0" fill="blue" />
  <text fill="yellow" stroke="yellow" y="55" x="0">A text</text>
</svg>nil



In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.43, cairo version 1.18.0) of 2025-01-28
Repository revision: 8c4a4b4eab8ac4dc26e65d552821f3f0b49c79c4
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: Fedora Linux 40 (KDE Plasma)

Configured using:
 'configure --with-native-compilation=no'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

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

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.
[dom-patch-V0.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#75928; Package emacs. (Wed, 05 Feb 2025 12:02:02 GMT) Full text and rfc822 format available.

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

From: David Ponce <da_vid <at> orange.fr>
To: 75928 <at> debbugs.gnu.org
Subject: Re: 31.0.50; `dom-print' often fails to print an SVG DOM
Date: Wed, 5 Feb 2025 13:01:04 +0100
[Message part 1 (text/plain, inline)]
Hello,

I attached a new patch that also avoid printing attributes without a
value (value is nil in the DOM).

I also refreshed the list of HTML boolean attributes from the current
standard, and put checking for a boolean attribute in a separate
inline function for clarity.

The patch also slightly improve the code by computing the indentation
column outside of loop and delegating indentation to `indent-line-to'.

Here is a change log:

2025-02-05  David Ponce  <da_vid <at> orange.fr>

	Fix DOM printing when an attribute value is not a string,
	which is often the case in SVG DOM.  Don't print attributes
	without a value.  Refresh the list of HTML boolean attributes.

	* dom.el (dom--html-boolean-attribute-p): New function.
	(dom-print): Use it.  Convert attribute value to string before
	to call `url-insert-entities-in-string'.  Don't print
	attribute without a value.  Compute indentation column outside
	of loop and call `indent-line-to' to indent line.

This new version passes the `dom-tests-print'.

Thanks!
[dom-patch-V1.patch (text/x-patch, attachment)]

Added tag(s) patch. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 05 Feb 2025 22:43:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#75928; Package emacs. (Sat, 08 Feb 2025 09:42:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: David Ponce <da_vid <at> orange.fr>
Cc: 75928 <at> debbugs.gnu.org
Subject: Re: bug#75928: 31.0.50; `dom-print' often fails to print an SVG DOM
Date: Sat, 08 Feb 2025 11:41:38 +0200
> Date: Wed, 5 Feb 2025 13:01:04 +0100
> From:  David Ponce via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> I attached a new patch that also avoid printing attributes without a
> value (value is nil in the DOM).
> 
> I also refreshed the list of HTML boolean attributes from the current
> standard, and put checking for a boolean attribute in a separate
> inline function for clarity.
> 
> The patch also slightly improve the code by computing the indentation
> column outside of loop and delegating indentation to `indent-line-to'.

Thanks.

Using indent-line-to requires binding indent-tabs-mode to nil, to make
sure we produce spaces and not TABs, right?

Also, please make sure the dom.el test suite still passes after this
change, if you haven't already.  Bonus points for providing a new test
for this feature.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#75928; Package emacs. (Sat, 08 Feb 2025 12:56:02 GMT) Full text and rfc822 format available.

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

From: David Ponce <da_vid <at> orange.fr>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 75928 <at> debbugs.gnu.org
Subject: Re: bug#75928: 31.0.50; `dom-print' often fails to print an SVG DOM
Date: Sat, 8 Feb 2025 13:55:16 +0100
[Message part 1 (text/plain, inline)]
On 2025-02-08 10:41, Eli Zaretskii wrote:
>> Date: Wed, 5 Feb 2025 13:01:04 +0100
>> From:  David Ponce via "Bug reports for GNU Emacs,
>>   the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>> I attached a new patch that also avoid printing attributes without a
>> value (value is nil in the DOM).
>>
>> I also refreshed the list of HTML boolean attributes from the current
>> standard, and put checking for a boolean attribute in a separate
>> inline function for clarity.
>>
>> The patch also slightly improve the code by computing the indentation
>> column outside of loop and delegating indentation to `indent-line-to'.
> 
> Thanks.
> 
> Using indent-line-to requires binding indent-tabs-mode to nil, to make
> sure we produce spaces and not TABs, right?
> 
> Also, please make sure the dom.el test suite still passes after this
> change, if you haven't already.  Bonus points for providing a new test
> for this feature.

Hello Eli,

Thank you very much for your feedback.

Please, find attached a new patch to force indent with spaces and to add
two new tests to dom-tests.el.

Here is the updated change log:

2025-02-08  David Ponce  <da_vid <at> orange.fr>

	Fix DOM printing when an attribute value is not a string, which is
	often the case in SVG DOM.  Don't print attributes without a
	value.  Refresh the list of HTML boolean attributes.

	* lisp/dom.el (dom--html-boolean-attribute-p): New function.
	(dom-print): Use it.  Convert attribute value to string before to
	call `url-insert-entities-in-string'.  Don't print attribute
	without a value.  Compute indentation column outside of loop and
	call `indent-line-to' to indent line.

	* test/lisp/dom-tests.el (dom-tests-print-svg)
	(dom-tests-print-html-boolean): New tests.

All tests in dom-tests.el passed for me:

Running 28 tests (2025-02-08 13:45:37+0100, selector `(not (or (tag :unstable) (tag :nativecomp)))')
   passed   1/28  dom-test-search (0.000180 sec)
   passed   2/28  dom-tests-add-child-before (0.000199 sec)
   passed   3/28  dom-tests-append-child (0.000074 sec)
   passed   4/28  dom-tests-attr (0.000096 sec)
   passed   5/28  dom-tests-attributes (0.000054 sec)
   passed   6/28  dom-tests-by-class (0.000074 sec)
   passed   7/28  dom-tests-by-id (0.000091 sec)
   passed   8/28  dom-tests-by-style (0.000054 sec)
   passed   9/28  dom-tests-by-tag (0.000052 sec)
   passed  10/28  dom-tests-child-by-tag (0.000047 sec)
   passed  11/28  dom-tests-children (0.000066 sec)
   passed  12/28  dom-tests-elements (0.000057 sec)
   passed  13/28  dom-tests-ensure-node (0.000071 sec)
   passed  14/28  dom-tests-non-text-children (0.000057 sec)
   passed  15/28  dom-tests-parent (0.000052 sec)
   passed  16/28  dom-tests-pp (0.000102 sec)
   passed  17/28  dom-tests-previous-sibling (0.000049 sec)
   passed  18/28  dom-tests-print (0.009147 sec)
   passed  19/28  dom-tests-print-html-boolean (0.000200 sec)
   passed  20/28  dom-tests-print-svg (0.000166 sec)
   passed  21/28  dom-tests-remove-attribute (0.000083 sec)
   passed  22/28  dom-tests-remove-node (0.000088 sec)
   passed  23/28  dom-tests-set-attribute (0.000039 sec)
   passed  24/28  dom-tests-set-attributes (0.000074 sec)
   passed  25/28  dom-tests-strings (0.000077 sec)
   passed  26/28  dom-tests-tag (0.000087 sec)
   passed  27/28  dom-tests-text (0.000065 sec)
   passed  28/28  dom-tests-texts (0.000047 sec)

Ran 28 tests, 28 results as expected, 0 unexpected (2025-02-08 13:45:37+0100, 0.012721 sec)
[dom-patch-V2.patch (text/x-patch, attachment)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 15 Feb 2025 11:51:02 GMT) Full text and rfc822 format available.

Notification sent to David Ponce <da_vid <at> orange.fr>:
bug acknowledged by developer. (Sat, 15 Feb 2025 11:51:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: David Ponce <da_vid <at> orange.fr>
Cc: 75928-done <at> debbugs.gnu.org
Subject: Re: bug#75928: 31.0.50; `dom-print' often fails to print an SVG DOM
Date: Sat, 15 Feb 2025 13:50:45 +0200
> Date: Sat, 8 Feb 2025 13:55:16 +0100
> Cc: 75928 <at> debbugs.gnu.org
> From: David Ponce <da_vid <at> orange.fr>
> 
> On 2025-02-08 10:41, Eli Zaretskii wrote:
> >> Date: Wed, 5 Feb 2025 13:01:04 +0100
> >> From:  David Ponce via "Bug reports for GNU Emacs,
> >>   the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> >>
> >> I attached a new patch that also avoid printing attributes without a
> >> value (value is nil in the DOM).
> >>
> >> I also refreshed the list of HTML boolean attributes from the current
> >> standard, and put checking for a boolean attribute in a separate
> >> inline function for clarity.
> >>
> >> The patch also slightly improve the code by computing the indentation
> >> column outside of loop and delegating indentation to `indent-line-to'.
> > 
> > Thanks.
> > 
> > Using indent-line-to requires binding indent-tabs-mode to nil, to make
> > sure we produce spaces and not TABs, right?
> > 
> > Also, please make sure the dom.el test suite still passes after this
> > change, if you haven't already.  Bonus points for providing a new test
> > for this feature.
> 
> Hello Eli,
> 
> Thank you very much for your feedback.
> 
> Please, find attached a new patch to force indent with spaces and to add
> two new tests to dom-tests.el.

Thanks, installed on the master branch, and closing the bug.




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

This bug report was last modified 97 days ago.

Previous Next


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