Commit d9da8a43 authored by Michal Čihař's avatar Michal Čihař

Fix handling of unicode in XML in Python 2

Fixes #996
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 05d3a102
......@@ -25,6 +25,8 @@ import re
from django.utils.translation import ugettext_lazy as _
import six
from weblate.trans.checks.base import TargetCheck
BBCODE_MATCH = re.compile(
......@@ -95,8 +97,14 @@ class XMLTagsCheck(TargetCheck):
'''
Wrapper for parsing XML.
'''
text = strip_entities(text)
return cElementTree.fromstring('<weblate>%s</weblate>' % text)
text = ''.join(
('<weblate>', strip_entities(text), '</weblate>')
)
if six.PY2:
text = text.encode('utf-8')
return cElementTree.fromstring(text)
def check_single(self, source, target, unit):
# Quick check if source looks like XML
......
......@@ -22,6 +22,7 @@
Tests for quality checks.
"""
from __future__ import unicode_literals
from weblate.trans.checks.markup import (
BBCodeCheck,
XMLTagsCheck,
......@@ -63,3 +64,6 @@ class XMLTagsCheckTest(CheckTestCase):
(24, 28, '</b>'),
]
)
def test_unicode(self):
self.do_test(False, ('<a>zkouška</a>', '<a>zkouška</a>', ''))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment