Skip to content

Commit

Permalink
Fix etree to string conversion in FeedGenerator
Browse files Browse the repository at this point in the history
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 <rss> was lost (e.g., adding a processing instruction `<?xml-stylesheet href="rss.xsl" type="text/xsl"?>` as sibling to <rss>).

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.
  • Loading branch information
chazeon committed Oct 2, 2023
1 parent ffe3e4d commit 1e9282d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions feedgen/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def atom_str(self, pretty=False, extensions=True, encoding='UTF-8',
<https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring>`_
'''
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,
Expand Down Expand Up @@ -396,7 +396,7 @@ def rss_str(self, pretty=False, extensions=True, encoding='UTF-8',
<https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring>`_
'''
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,
Expand Down

0 comments on commit 1e9282d

Please sign in to comment.