* [sand@blarg.net: [PATCH] xml-debug-print-internal needs to quote attributes and text]
@ 2007-12-17 17:22 Richard Stallman
2007-12-18 3:31 ` [PATCH] xml-debug-print-internal needs to quote attributes and text Mark A. Hershberger
0 siblings, 1 reply; 3+ messages in thread
From: Richard Stallman @ 2007-12-17 17:22 UTC (permalink / raw)
To: emacs-devel
Would someone please DTRT and ack?
------- Start of forwarded message -------
X-Spam-Status: No, score=0.6 required=5.0 tests=NO_REAL_NAME,SPF_PASS,
UNPARSEABLE_RELAY autolearn=no version=3.1.0
Date: 17 Dec 2007 04:28:47 -0000
Message-ID: <20071217042847.31231.qmail@priss.frightenedpiglet.com>
From: sand@blarg.net
To: bug-gnu-emacs@gnu.org
Subject: [PATCH] xml-debug-print-internal needs to quote attributes and text
Load xml.el to define `xml-debug-print' and evaluate the following:
(xml-debug-print
'((foo ((attr . "<bar> & \"<bar>\"")) "<bar> & \"<bar>\"")))
This will insert text into the current buffer. With the as-shipped
`xml-debug-print' definition, the buffer gets:
<foo attr="<bar> & "<bar>""><bar> & "<bar>"</foo>
This is not legal XML. We have legal XML if we escape greater-than,
less-than and ampersand in the attribute value and in the content, and
escape quote in the attribute value:
<foo attr="<bar> & "<bar>""><bar> & "<bar>"</foo>
The XML specifiction <http://www.w3.org/TR/REC-xml/#syntax> allows
some leeway in the exact behavior, but the above substitutions are
compliant. In particular, we do not escape apostrophes in the
attribute value, since the code never quotes attribute values using
apostrophes.
The following redefinition of `xml-debug-print-internal' performs
regexp substitution for each of the quotable characters. Note that
the replacement lists are different for the two cases.
(defun xml-debug-print-internal (xml indent-string)
"Outputs the XML tree in the current buffer.
The first line is indented with INDENT-STRING."
(let ((tree xml)
attlist)
(insert indent-string ?< (symbol-name (xml-node-name tree)))
;; output the attribute list
(setq attlist (xml-node-attributes tree))
(while attlist
(let ((value (cdar attlist))
(replacements '(("&" . "&")
("<" . "<")
(">" . ">")
("\"" . """))))
(while replacements
(setq value (replace-regexp-in-string (caar replacements)
(cdar replacements)
value))
(setq replacements (cdr replacements)))
(insert ?\ (symbol-name (caar attlist)) "=\"" value ?\"))
(setq attlist (cdr attlist)))
(setq tree (xml-node-children tree))
(if (null tree)
(insert ?/ ?>)
(insert ?>)
;; output the children
(dolist (node tree)
(cond
((listp node)
(insert ?\n)
(xml-debug-print-internal node (concat indent-string " ")))
((stringp node)
(let ((replacements '(("&" . "&")
("<" . "<")
(">" . ">"))))
(while replacements
(setq node (replace-regexp-in-string (caar replacements)
(cdar replacements)
node))
(setq replacements (cdr replacements)))
(insert node)))
(t
(error "Invalid XML tree"))))
(when (not (and (null (cdr tree))
(stringp (car tree))))
(insert ?\n indent-string))
(insert ?< ?/ (symbol-name (xml-node-name xml)) ?>))))
In GNU Emacs 22.1.1 (i486-pc-linux-gnu, GTK+ Version 2.12.1)
of 2007-11-03 on pacem, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.10400000
configured using `configure '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs22:/etc/emacs:/usr/local/share/emacs/22.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/22.1/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/22.1/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2''
Derek
- --
Derek Upham
sand@blarg.net
"Ha! Your Leaping Tiger Kung Fu is no match for my Frightened Piglet style!"
------- End of forwarded message -------
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] xml-debug-print-internal needs to quote attributes and text
2007-12-17 17:22 [sand@blarg.net: [PATCH] xml-debug-print-internal needs to quote attributes and text] Richard Stallman
@ 2007-12-18 3:31 ` Mark A. Hershberger
2007-12-21 0:33 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Mark A. Hershberger @ 2007-12-18 3:31 UTC (permalink / raw)
To: emacs-devel
<sand@blarg.net> writes:
> Load xml.el to define `xml-debug-print' and evaluate the following:
>
> (xml-debug-print
> '((foo ((attr . "<bar> & \"<bar>\"")) "<bar> & \"<bar>\"")))
Fixed by creating xml-escape-string and using it in xml-debug-print.
--
http://hexmode.com/
GPG Fingerprint: 7E15 362D A32C DFAB E4D2 B37A 735E F10A 2DFC BFF5
The most beautiful experience we can have is the mysterious.
-- Albert Einstein, The World As I See it
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xml-debug-print-internal needs to quote attributes and text
2007-12-18 3:31 ` [PATCH] xml-debug-print-internal needs to quote attributes and text Mark A. Hershberger
@ 2007-12-21 0:33 ` Stefan Monnier
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2007-12-21 0:33 UTC (permalink / raw)
To: Mark A. Hershberger; +Cc: emacs-devel
>> Load xml.el to define `xml-debug-print' and evaluate the following:
>>
>> (xml-debug-print
>> '((foo ((attr . "<bar> & \"<bar>\"")) "<bar> & \"<bar>\"")))
> Fixed by creating xml-escape-string and using it in xml-debug-print.
Note that the name `xml-debug-print' indicates clearly that this is not
intended to be used as a real printer function. So if it's not the case
any more, it should be renamed to `xml-print' or somesuch.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-12-21 0:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-17 17:22 [sand@blarg.net: [PATCH] xml-debug-print-internal needs to quote attributes and text] Richard Stallman
2007-12-18 3:31 ` [PATCH] xml-debug-print-internal needs to quote attributes and text Mark A. Hershberger
2007-12-21 0:33 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.