Skip to content

Unhandled ValueError raised in read_po #1209

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

Open
gabe-sherman opened this issue May 12, 2025 · 2 comments
Open

Unhandled ValueError raised in read_po #1209

gabe-sherman opened this issue May 12, 2025 · 2 comments

Comments

@gabe-sherman
Copy link
Contributor

The below code triggers an exception with the following message: ValueError: invalid literal for int() with base 10: '\x0c'. This occurs in _process_keyword_line at line 251 in pofile.py as a result of a failure to check the validity of an integer conversion.

import io
from babel.messages.pofile import read_po

data = io.StringIO("msgstr[\x0c]")
read_po(data)

Version

2.17.0

Trace report

Traceback (most recent call last):
  File "rep.py", line 5, in <module>
    read_po(data)
  File "lib/python3.10/site-packages/babel/messages/pofile.py", line 406, in read_po
    parser.parse(fileobj)
  File "lib/python3.10/site-packages/babel/messages/pofile.py", line 331, in parse
    self._process_message_line(lineno, line)
  File "lib/python3.10/site-packages/babel/messages/pofile.py", line 221, in _process_message_line
    self._process_keyword_line(lineno, line, obsolete)
  File "/lib/python3.10/site-packages/babel/messages/pofile.py", line 251, in _process_keyword_line
    idx = int(idxarg[:-1]) if has_bracket else 0
ValueError: invalid literal for int() with base 10: '\x0c'
@akx
Copy link
Member

akx commented May 13, 2025

Hi, thank you for the report.

Do you have a link to a .po file "in the wild" that exhibits a msgstr keyword having an argument like that? As far as I can tell from the spec, as it were, plural msgstrs are expected to have numeric indices.

@gabe-sherman
Copy link
Contributor Author

I see, I understand what you mean. In this case, since it's an invalid .po file, maybe a PoFileError should be raised to better reflect to the user that the file is invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants