; Use HTML entities for reserved characters in 'dom-print'

* lisp/dom.el (dom-print): Encode HTML reserved characters in strings.
* test/lisp/dom-tests.el (dom-tests-print): New test.  (Bug#68508)
This commit is contained in:
Eshel Yaron 2024-01-05 16:40:44 +01:00 committed by Eli Zaretskii
parent b3e4fbe867
commit 3a5ee06057
2 changed files with 11 additions and 1 deletions

View file

@ -288,7 +288,7 @@ If XML, generate XML instead of HTML."
(insert ">")
(dolist (child children)
(if (stringp child)
(insert child)
(insert (url-insert-entities-in-string child))
(setq non-text t)
(when pretty
(insert "\n" (make-string (+ column 2) ?\s)))

View file

@ -209,6 +209,16 @@ child results in an error."
(dom-pp node t)
(should (equal (buffer-string) "(\"foo\" nil)")))))
(ert-deftest dom-tests-print ()
"Test that `dom-print' correctly encodes HTML reserved characters."
(with-temp-buffer
(dom-print '(samp ((class . "samp")) "<div class=\"default\"> </div>"))
(should (equal
(buffer-string)
(concat "<samp class=\"samp\">"
"&lt;div class=&quot;default&quot;&gt; &lt;/div&gt;"
"</samp>")))))
(ert-deftest dom-test-search ()
(let ((dom '(a nil (b nil (c nil)))))
(should (equal (dom-search dom (lambda (d) (eq (dom-tag d) 'a)))