-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for ]]> in CDATA in minidom #64913
Comments
Current support for ]]> inside CDATA is to raise an Exception. However, it could be solved by dividing the ]]> to two strings:
|
Does the XML spec allow that? |
Eric, I'm not sure what exactly your concern is, but I'll try to address two issues I can see. First: both strings <![CDATA[]]]]> and <![CDATA[>]]> are a correct and valid examples of CDATA usage as per specification[1]. Second: is it allowed to have two occurences of CDATA inside one element? The same specification says only that ‟CDATA sections may occur anywhere character data may occur”. There is nothing said if multiple occurrences are allowed or disallowed. Last but not least: using following schema: <?xml version="1.0" encoding="UTF-8"?> following XML file: <?xml version="1.0" ?> validates correctly with xmllint: I hope it dissolves your concerns. PS. I noticed I missed one ] in provided patch. There should be four of them in second parameter of replace. [1] http://www.w3.org/TR/REC-xml/#sec-cdata-sect |
Proper patch with tests available in remote hg repo attached to this comment. |
Artur: Please provide the follwing information (in this bug report, or in any other bug report you create in the future)
I fail to see how "two CDATA sections in one element" are related to "support for ]]> inside CDATA". In your example, there is no ]]> inside CDATA, just two subsequent CDATA sections. |
Martin, the exact information you need are:
#!/usr/bin/env python
import unittest
import xmlrunner
class Foo(unittest.TestCase):
def testFoo(self):
self.assertTrue(False, ']]>')
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
Running tests... Traceback (most recent call last):
File "./cdata.py", line 7, in testFoo
self.assertTrue(False, ']]>')
AssertionError: ]]> Ran 1 test in 0.001s FAILED (failures=1) Generating XML reports...
Traceback (most recent call last):
File "./cdata.py", line 9, in <module>
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
File "/usr/lib/python2.7/unittest/main.py", line 95, in __init__
self.runTests()
File "/usr/lib/python2.7/unittest/main.py", line 232, in runTests
self.result = testRunner.run(self.test)
File "/usr/lib/python2.7/dist-packages/xmlrunner/__init__.py", line 415, in run
result.generate_reports(self)
File "/usr/lib/python2.7/dist-packages/xmlrunner/__init__.py", line 312, in generate_reports
xml_content = doc.toprettyxml(indent='\t')
File "/usr/lib/python2.7/xml/dom/minidom.py", line 58, in toprettyxml
self.writexml(writer, "", indent, newl, encoding)
File "/usr/lib/python2.7/xml/dom/minidom.py", line 1749, in writexml
node.writexml(writer, indent, addindent, newl)
File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
node.writexml(writer, indent+addindent, addindent, newl)
File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
node.writexml(writer, indent+addindent, addindent, newl)
File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
node.writexml(writer, indent+addindent, addindent, newl)
File "/usr/lib/python2.7/xml/dom/minidom.py", line 1150, in writexml
raise ValueError("']]>' not allowed in a CDATA section")
ValueError: ']]>' not allowed in a CDATA section and empty directory test-reports has been created.
Running tests... Traceback (most recent call last):
File "./cdata.py", line 7, in testFoo
self.assertTrue(False, ']]>')
AssertionError: ]]> Ran 1 test in 0.001s FAILED (failures=1) Generating XML reports... and file test-reports/TEST-Foo-${timestamp}.xml is created with following content:
<?xml version="1.0" ?>
<testsuite errors="0" failures="1" name="Foo-20140223203423" tests="1" time="0.000">
<testcase classname="Foo" name="testFoo" time="0.000">
<failure message="]]>" type="AssertionError">
<![CDATA[Traceback (most recent call last):
File "./cdata.py", line 7, in testFoo
self.assertTrue(False, ']]]]><![CDATA[>')
AssertionError: ]]]]><![CDATA[>
]]> </failure>
</testcase>
<system-out>
<![CDATA[]]> </system-out>
<system-err>
<![CDATA[]]> </system-err>
</testsuite> however, on the level of minidom.py module, there is an exact test provided in attached repository. PS. I removed the patch by purpose - it's wrong and someone could be misleaded by it. The correct solution I propose is in the attached repository. |
I fail to see the bug in Python. minidom is behaving correctly. The error is in xmlrunner, which does error_info = str(test_result.get_error_info())
failureText = xml_document.createCDATASection(error_info) This is incorrect - it would have to check that error_info does not contain ]]> (since CDATA sections must not contain ]]>). If it finds ]]> in the error_info, it would have to create two CDATA sections, e.g. one up to and including ]], and the second one starting at > (repeated if there is more than one occurrence of ]]> in error_info. Alternatively, it should just create a text node, since writing a text node will properly escape all special characters in error_info. |
Martin, If you disagree, feel free to close this issue. |
I don't think your proposal can be implemented. createXYZ, in DOM, only creates a single node, which is not yet attached at all into a tree. So if you would want a convenience function to create multiple CDATA section, the application would then still have to loop over them to insert them individually into the tree. Personally, I would not have my application create multiple CDATA sections. Instead, I would use if ']]>' in error_info:
failureText = xml_document.createTextNode(error_info)
else:
failureText = xml_document.createCDATASection(error_info) instead. So I doubt that all application authors would really agree on a single solution to this problem. Closing this as "won't fix". |
Perhaps a look at the competition is still in order: Java silently breaks such an invalid CDATA in two, as suggested. http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.htm says The change Artur suggested would be covered by this. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: