From 1e9282d0c922f6aab649554d2939dcf68341503b Mon Sep 17 00:00:00 2001 From: Chenxing Luo Date: Mon, 2 Oct 2023 11:09:09 -0400 Subject: [PATCH] Fix etree to string conversion in FeedGenerator When converting `feed` object to a string, using `atom_str` or `rss_str` methods, with `etree.tostring` method, `feed` instead of `doc` is supplied. In this case, changes applied outside the was lost (e.g., adding a processing instruction `` as sibling to ). The `feed` object has now been replaced by the `doc` object in both the `_create_atom` and `_create_rss` methods, ensuring the correct conversion and preventing possible lost of information in the feed generation. --- feedgen/feed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feedgen/feed.py b/feedgen/feed.py index 9ebd219..fa82702 100644 --- a/feedgen/feed.py +++ b/feedgen/feed.py @@ -220,7 +220,7 @@ def atom_str(self, pretty=False, extensions=True, encoding='UTF-8', `_ ''' feed, doc = self._create_atom(extensions=extensions) - return etree.tostring(feed, pretty_print=pretty, encoding=encoding, + return etree.tostring(doc, pretty_print=pretty, encoding=encoding, xml_declaration=xml_declaration) def atom_file(self, filename, extensions=True, pretty=False, @@ -396,7 +396,7 @@ def rss_str(self, pretty=False, extensions=True, encoding='UTF-8', `_ ''' feed, doc = self._create_rss(extensions=extensions) - return etree.tostring(feed, pretty_print=pretty, encoding=encoding, + return etree.tostring(doc, pretty_print=pretty, encoding=encoding, xml_declaration=xml_declaration) def rss_file(self, filename, extensions=True, pretty=False,