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

pybabel extract crashes when it encounters a byte string #1190

Open
tomasr8 opened this issue Feb 13, 2025 · 0 comments
Open

pybabel extract crashes when it encounters a byte string #1190

tomasr8 opened this issue Feb 13, 2025 · 0 comments

Comments

@tomasr8
Copy link
Member

tomasr8 commented Feb 13, 2025

(Happens on current master)

Sample file:

_(b'foo')

now run pybabel extract test.py -o messages.pot and you'll get this error:

> pybabel extract test.py -o messages.pot
extracting messages from test.py
Traceback (most recent call last):
  File "/home/dev/babel/venv/bin/pybabel", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/dev/babel/babel/messages/frontend.py", line 998, in main
    return CommandLineInterface().run(sys.argv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dev/babel/babel/messages/frontend.py", line 924, in run
    return cmdinst.run()
           ^^^^^^^^^^^^^
  File "/home/dev/babel/babel/messages/frontend.py", line 522, in run
    for filename, lineno, message, comments, context in extracted:
                                                        ^^^^^^^^^
  File "/home/dev/babel/babel/messages/extract.py", line 282, in check_and_call_extract_file
    for message_tuple in extract_from_file(
                         ^^^^^^^^^^^^^^^^^^
  File "/home/dev/babel/babel/messages/extract.py", line 324, in extract_from_file
    return list(extract(method, fileobj, keywords, comment_tags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dev/babel/babel/messages/extract.py", line 451, in extract
    for lineno, funcname, messages, comments in results:
                                                ^^^^^^^
  File "/home/dev/babel/babel/messages/extract.py", line 562, in extract_python
    messages.append(''.join(buf))
                    ^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, bytes found

It seems like we're trying to call .join() on a byte string. I suggest just fixing the crash but keeping byte strings disallowed - they won't work with gettext anyway because gettext uses normal strings internally.

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