[Python-bugs-list] [ python-Bugs-440351 ] saxutils.escape needs to escape "quotes"

noreply@sourceforge.net noreply@sourceforge.net
Thu, 19 Jul 2001 09:11:22 -0700


Bugs item #440351, was opened at 2001-07-11 03:32
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=440351&group_id=5470

Category: XML
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Andrew Dalke (dalke)
>Assigned to: Fred L. Drake, Jr. (fdrake)
>Summary: saxutils.escape needs to escape "quotes"

Initial Comment:
XML attributes containing a value with a double
quote are not properly escaped.  Consider

from xml.sax import saxutils
gen = saxutils.XMLGenerator()
gen.startDocument()
gen.startElement('spam', {'width': '12"'})

This produces

<?xml version="1.0" encoding="iso-8859-1"?>
<spam width="12"">

That second line should more likely be

<spam width="12&quot;">

or perhaps use the hex escape, which I think
is '&#23'.  But I'm not an XML guru so don't
trust me on either one!

                               Andrew Dalke
                               dalke@acm.org


----------------------------------------------------------------------

>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-07-19 09:11

Message:
Logged In: YES 
user_id=3066

Fixed, but not in the way requested.  ;-)

I've added a new function to the saxutils module,
quoteattr().  It prepares an attribute value for inclusion
as part of markup by doing "just enough" escaping of quote
characters, and supplies the proper quote characters for the
escaping it actually did.

The addition was checked in as Lib/xml/sax/saxutils.py
revision 1.15, with corresponding documentation and test
updates.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=440351&group_id=5470