Skip to content
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

io.StringIO not working in parse() #427

Open
murrple-1 opened this issue Jan 7, 2024 · 0 comments
Open

io.StringIO not working in parse() #427

murrple-1 opened this issue Jan 7, 2024 · 0 comments

Comments

@murrple-1
Copy link

Using version 6.0.11 and Python 3.12

The docs for parse() say

...snip...
Wrap an untrusted string in a :class:`io.StringIO` or :class:`io.BytesIO` to avoid this. Do not pass untrusted strings to this function.
...snip...

If you pass an io.BytesIO, this works fine:

>>> import feedparser
>>> import io
>>> feedparser.parse(io.BytesIO(b"<rss></rss>"))
{'bozo': False, 'entries': [], 'feed': {}, 'headers': {}, 'encoding': 'utf-8', 'version': 'rss', 'namespaces': {}}

However, if you pass a io.StringIO, it crashes:

>>> import feedparser
>>> import io
>>> feedparser.parse(io.StringIO("<rss></rss>"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mchristo/.local/share/virtualenvs/rss_temple-pQQQnncW/lib/python3.12/site-packages/feedparser/api.py", line 230, in parse
    data = convert_to_utf8(result['headers'], data, result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mchristo/.local/share/virtualenvs/rss_temple-pQQQnncW/lib/python3.12/site-packages/feedparser/encodings.py", line 189, in convert_to_utf8
    xml_encoding_match = RE_XML_PI_ENCODING.match(tempdata)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot use a bytes pattern on a string-like object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant