emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r109678: * xml.el (xml-escape-string)


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109678: * xml.el (xml-escape-string): Don't refer to xml-entity-alist.
Date: Sun, 19 Aug 2012 14:37:15 +0800
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109678
fixes bug: http://debbugs.gnu.org/12228
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sun 2012-08-19 14:37:15 +0800
message:
  * xml.el (xml-escape-string): Don't refer to xml-entity-alist.
modified:
  lisp/ChangeLog
  lisp/xml.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-08-18 05:11:38 +0000
+++ b/lisp/ChangeLog    2012-08-19 06:37:15 +0000
@@ -1,3 +1,8 @@
+2012-08-19  Chong Yidong  <address@hidden>
+
+       * xml.el (xml-escape-string): Don't refer to xml-entity-alist
+       (Bug#12228).
+
 2012-08-18  Chong Yidong  <address@hidden>
 
        * simple.el (yank-handled-properties): New defcustom.

=== modified file 'lisp/xml.el'
--- a/lisp/xml.el       2012-07-28 09:19:53 +0000
+++ b/lisp/xml.el       2012-08-19 06:37:15 +0000
@@ -1011,13 +1011,25 @@
 (defalias 'xml-print 'xml-debug-print)
 
 (defun xml-escape-string (string)
-  "Return STRING with entity substitutions made from `xml-entity-alist'."
-  (mapconcat (lambda (byte)
-               (let ((char (char-to-string byte)))
-                 (if (rassoc char xml-entity-alist)
-                     (concat "&" (car (rassoc char xml-entity-alist)) ";")
-                   char)))
-             string ""))
+  "Convert STRING into a string containing valid XML character data.
+Replace occurrences of &<>'\" in STRING with their default XML
+entity references (e.g. replace each & with &amp;).
+
+XML character data must not contain & or < characters, nor the >
+character under some circumstances.  The XML spec does not impose
+restriction on \" or ', but we just substitute for these too
+\(as is permitted by the spec)."
+  (with-temp-buffer
+    (insert string)
+    (dolist (substitution '(("&" . "&amp;")
+                           ("<" . "&lt;")
+                           (">" . "&gt;")
+                           ("'" . "&apos;")
+                           ("\"" . "&quot;")))
+      (goto-char (point-min))
+      (while (search-forward (car substitution) nil t)
+       (replace-match (cdr substitution) t t nil)))
+    (buffer-string)))
 
 (defun xml-debug-print-internal (xml indent-string)
   "Outputs the XML tree in the current buffer.


reply via email to

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