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

Traceback with non-ascii header key #3896

Closed
friedelwolff opened this issue Jun 6, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@friedelwolff
Copy link
Member

commented Jun 6, 2019

If a PO header contains a non-ASCII key (left of the colon), we have a traceback. An example is file here:
https://gitlab.gnome.org/GNOME/gimp/blob/master/po-python/oc.po#L21

The traceback comes from poheader.gettargetlanguage():

  File "env/lib/python2.7/site-packages/translate/storage/poheader.py", line 286, in gettargetlanguage
    header = self.parseheader()
  File "env/lib/python2.7/site-packages/translate/storage/poheader.py", line 219, in parseheader
    return parseheaderstring(header.target)
  File "env/lib/python2.7/site-packages/translate/storage/poheader.py", line 52, in parseheaderstring
    key = str(key.strip())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 4: ordinal not in range(128)

I don't have a usable toolkit environment configured, so anybody is free to fix this if they can/want. I guess translate/storage/poheader.py::parseheaderstring() line 52 the str(key.strip()) could probably just be without the str(), but we'll have to check the tests. Also, I think in some places header dictionaries might be passed as **kwargs, and non-ascii values might not work in Python 2, so I'm not sure it is a trivial change.

nijel added a commit to nijel/translate that referenced this issue Jun 7, 2019

nijel added a commit to nijel/translate that referenced this issue Jun 7, 2019

@nijel

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2019

Your suggested fix seems to work well, **kwargs works fine with unicode keys in Python 2.7, so it looks safe. See #3897

@nijel nijel self-assigned this Jun 7, 2019

@nijel nijel added the formats label Jun 7, 2019

nijel added a commit to nijel/translate that referenced this issue Jun 7, 2019

@nijel nijel closed this in #3897 Jun 21, 2019

nijel added a commit that referenced this issue Jun 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.