Skip to content

Can't handle non-ASCII characters #28

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

Closed
desolat opened this issue Jun 18, 2015 · 0 comments
Closed

Can't handle non-ASCII characters #28

desolat opened this issue Jun 18, 2015 · 0 comments

Comments

@desolat
Copy link
Contributor

desolat commented Jun 18, 2015

The module is not able to handle input with non-ASCII characters. If unicode is passed, the str() conversion on most of the parameters throws UnicodeEncodeErrors as the Python default encoding of ASCII is not able to handle the non-ASCII characters.

If UTF-8 encoded strings are passed, etree's element.tostring() method is expecting unicode and tries to encode it:

  File "C:\python27\lib\site-packages\junit_xml\__init__.py", line 169, in to_xml_string
    xml_string = ET.tostring(xml_element, encoding=encoding)
  File "C:\python27\lib\xml\etree\ElementTree.py", line 1126, in tostring
    ElementTree(element).write(file, encoding, method=method)
  File "C:\python27\lib\xml\etree\ElementTree.py", line 820, in write
    serialize(write, self._root, encoding, qnames, namespaces)
  File "C:\python27\lib\xml\etree\ElementTree.py", line 939, in _serialize_xml
    _serialize_xml(write, e, encoding, qnames, None)
  File "C:\python27\lib\xml\etree\ElementTree.py", line 932, in _serialize_xml
    v = _escape_attrib(v, encoding)
  File "C:\python27\lib\xml\etree\ElementTree.py", line 1090, in _escape_attrib
    return text.encode(encoding, "xmlcharrefreplace")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)

The workaround of changing Python's default encoding is considered evil and not always an option.
It could be possible to internally only use unicode and check and convert all input.

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