summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChong Yidong <cyd@gnu.org>2012-08-19 14:37:15 +0800
committerChong Yidong <cyd@gnu.org>2012-08-19 14:37:15 +0800
commit17975d7ff9fd734e67dfb97dc9f8be45fcdaec7c (patch)
tree1c1f0a71698006a4a93bd6433ac7b5b3525598db
parentd7191076ce331e8c78dbc93b76d0e346c268daa0 (diff)
downloademacs-17975d7ff9fd734e67dfb97dc9f8be45fcdaec7c.tar.gz
* xml.el (xml-escape-string): Don't refer to xml-entity-alist.
Fixes: debbugs:12228
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/xml.el26
2 files changed, 24 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ec89b3784d9..17c7fa0f06a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2012-08-19 Chong Yidong <cyd@gnu.org>
+
+ * xml.el (xml-escape-string): Don't refer to xml-entity-alist
+ (Bug#12228).
+
2012-08-18 Chong Yidong <cyd@gnu.org>
* simple.el (yank-handled-properties): New defcustom.
diff --git a/lisp/xml.el b/lisp/xml.el
index 179fdd6b5cc..d395f75ec0f 100644
--- a/lisp/xml.el
+++ b/lisp/xml.el
@@ -1011,13 +1011,25 @@ The first line is indented with the optional INDENT-STRING."
(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.