From d0f59054d0c4b2291a4e0e94ec00537f98a4ab50 Mon Sep 17 00:00:00 2001 From: Georg Sauthoff Date: Fri, 10 Feb 2017 15:29:34 +0100 Subject: Fixed #28324 -- Made feedgenerators write feeds with deterministically ordered attributes. --- django/utils/xmlutils.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'django/utils/xmlutils.py') diff --git a/django/utils/xmlutils.py b/django/utils/xmlutils.py index f1edfb2ac9..6b62a1fe74 100644 --- a/django/utils/xmlutils.py +++ b/django/utils/xmlutils.py @@ -3,6 +3,7 @@ Utilities for XML generation/parsing. """ import re +from collections import OrderedDict from xml.sax.saxutils import XMLGenerator @@ -26,3 +27,8 @@ class SimplerXMLGenerator(XMLGenerator): # See http://www.w3.org/International/questions/qa-controls raise UnserializableContentError("Control characters are not supported in XML 1.0") XMLGenerator.characters(self, content) + + def startElement(self, name, attrs): + # Sort attrs for a deterministic output. + sorted_attrs = OrderedDict(sorted(attrs.items())) if attrs else attrs + super().startElement(name, sorted_attrs) -- cgit v1.3