[XML-SIG] Builder doesn't quote ' or " properly?
Anthony Baxter
Anthony Baxter <anthony@interlink.com.au>
Sat, 13 May 2000 00:41:41 +1000
>>> "Andrew M. Kuchling" wrote
> Anthony Baxter writes:
> >Suggestions? Should I be quoting this by hand? Should I be hunting into
> >the code to find out where it's getting it wrong?
>
> It's clearly a bug; the toxml() method of the Element class should be
> escaping ' in attributes. The " doesn't need to be escaped inside an
> attribute surrounded by ' characters, though.
with that pointer, finding the problem was relatively easy.
Rather than unconditionally quoting ' in xml.utils.escape, I
only did it for xml.dom.core.Element.toxml
Would replacing the three 'string.replace' calls in xml.utils.escape
with a regex be a worthwhile optimisation?
patch is against CVS version, if that helps.
*** xml/dom/core.py.dist Sat May 13 00:38:20 2000
--- xml/dom/core.py Sat May 13 00:38:47 2000
***************
*** 870,876 ****
append(" %s='" % (attr,))
for value in attrnode.children:
if value.type == TEXT_NODE:
! append(escape(value.value) )
else:
n = NODE_CLASS[ value.type ] (value, self._document)
append(value.toxml())
--- 870,876 ----
append(" %s='" % (attr,))
for value in attrnode.children:
if value.type == TEXT_NODE:
! append(escape(value.value, {"'":"'"}) )
else:
n = NODE_CLASS[ value.type ] (value, self._document)
append(value.toxml())
Anthony