emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 3a5ee060571: ; Use HTML entities for reserved characters in 'dom-


From: Eli Zaretskii
Subject: master 3a5ee060571: ; Use HTML entities for reserved characters in 'dom-print'
Date: Sat, 20 Jan 2024 04:42:03 -0500 (EST)

branch: master
commit 3a5ee060571b29474f83ebaee11df6920ea68c6a
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    ; 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)
---
 lisp/dom.el            |  2 +-
 test/lisp/dom-tests.el | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/dom.el b/lisp/dom.el
index f7043ba8252..b329379fdc3 100644
--- a/lisp/dom.el
+++ b/lisp/dom.el
@@ -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)))
diff --git a/test/lisp/dom-tests.el b/test/lisp/dom-tests.el
index 8cbfb9ad9df..a4e913541bf 100644
--- a/test/lisp/dom-tests.el
+++ b/test/lisp/dom-tests.el
@@ -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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]