mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #20197 -- Made XML serializer fail loudly when outputting unserializable chars
Thanks Tim Graham for the review.
This commit is contained in:
@@ -371,6 +371,21 @@ class XmlSerializerTestCase(SerializersTestBase, TestCase):
|
||||
ret_list.append("".join(temp))
|
||||
return ret_list
|
||||
|
||||
def test_control_char_failure(self):
|
||||
"""
|
||||
Serializing control characters with XML should fail as those characters
|
||||
are not supported in the XML 1.0 standard (except HT, LF, CR).
|
||||
"""
|
||||
self.a1.headline = "This contains \u0001 control \u0011 chars"
|
||||
msg = "Article.headline (pk:%s) contains unserializable characters" % self.a1.pk
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
serializers.serialize(self.serializer_name, [self.a1])
|
||||
self.a1.headline = "HT \u0009, LF \u000A, and CR \u000D are allowed"
|
||||
self.assertIn(
|
||||
"HT \t, LF \n, and CR \r are allowed",
|
||||
serializers.serialize(self.serializer_name, [self.a1])
|
||||
)
|
||||
|
||||
|
||||
class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
|
||||
serializer_name = "xml"
|
||||
|
||||
Reference in New Issue
Block a user