Fixed mixed text and elements bug in tostring.
XML of the form <a>foo <b>bar</b> baz</a> was outputted as <a>foo <b>bar</b> baz baz</a>. Includes unit test.
This commit is contained in:
		@@ -68,9 +68,6 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None, outbuffer=''):
 | 
				
			|||||||
            for child in xml.getchildren():
 | 
					            for child in xml.getchildren():
 | 
				
			||||||
                output.append(tostring(child, tag_xmlns, stanza_ns, stream))
 | 
					                output.append(tostring(child, tag_xmlns, stanza_ns, stream))
 | 
				
			||||||
        output.append(u"</%s>" % tag_name)
 | 
					        output.append(u"</%s>" % tag_name)
 | 
				
			||||||
        if xml.tail:
 | 
					 | 
				
			||||||
            # If there is additional text after the element.
 | 
					 | 
				
			||||||
            output.append(xml_escape(xml.tail))
 | 
					 | 
				
			||||||
    elif xml.text:
 | 
					    elif xml.text:
 | 
				
			||||||
        # If we only have text content.
 | 
					        # If we only have text content.
 | 
				
			||||||
        output.append(u">%s</%s>" % (xml_escape(xml.text), tag_name))
 | 
					        output.append(u">%s</%s>" % (xml_escape(xml.text), tag_name))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,6 +73,16 @@ class TestToString(SleekTest):
 | 
				
			|||||||
            message="The xmlns parameter was not used properly.",
 | 
					            message="The xmlns parameter was not used properly.",
 | 
				
			||||||
            xmlns='foo')
 | 
					            xmlns='foo')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def testTailContent(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Test that elements of the form <a>foo <b>bar</b> baz</a> only
 | 
				
			||||||
 | 
					        include " baz" once.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        self.tryTostring(
 | 
				
			||||||
 | 
					            original='<a>foo <b>bar</b> baz</a>',
 | 
				
			||||||
 | 
					            message='Element tail content is incorrect.')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def testStanzaNs(self):
 | 
					    def testStanzaNs(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Test using the stanza_ns tostring parameter, which will prevent
 | 
					        Test using the stanza_ns tostring parameter, which will prevent
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user