Opened 6 years ago

Last modified 5 years ago

#3623 defect new

twisted.words.xish.domish.Element.addContent doesn't take SerializedXml into account

Reported by: ralphm Owned by:
Priority: normal Milestone:
Component: words Keywords:
Cc: Branch:
Author: Launchpad Bug:

Description

Using addContent on an Element when the last child is added by addRawXml, the latter gets improperly escaped.

The problem is best illustrated by the following:

>>> e = domish.Element((None, 'test'))
>>> e.addRawXml('<a/>')
>>> e.toXml()
u'<test><a/></test>'
>>> e.addContent('blah')
u'<a/>blah'
>>> e.toXml()
u'<test>&lt;a/&gt;blah</test>'

The call to addRawXml adds a SerializedXml object as child. This class derives from unicode to mark that the content should not be escaped. It adds no further functionality. However, addContent checks if the last child of the Element is an instance of one of the StringTypes, which is true also for SerializedXml and happily adds the new content, replacing the SerializedXml object and thus the marking.

Change History (3)

comment:1 Changed 6 years ago by ralphm

  • Summary changed from twisted.words.xish.domish.Element.addElement doesn't take SerializedXml into account to twisted.words.xish.domish.Element.addContent doesn't take SerializedXml into account

comment:2 Changed 5 years ago by exarkun

  • Milestone Twisted-8.2+1 deleted

I can't see any reason this needs to be targeted at 9.0 (8.2+1).

comment:3 Changed 4 years ago by <automation>

  • Owner ralphm deleted
Note: See TracTickets for help on using tickets.