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 ...@@ -25,6 +25,8 @@ import re
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import six
from weblate.trans.checks.base import TargetCheck from weblate.trans.checks.base import TargetCheck
BBCODE_MATCH = re.compile( BBCODE_MATCH = re.compile(
...@@ -95,8 +97,14 @@ class XMLTagsCheck(TargetCheck): ...@@ -95,8 +97,14 @@ class XMLTagsCheck(TargetCheck):
''' '''
Wrapper for parsing XML. Wrapper for parsing XML.
''' '''
text = strip_entities(text) text = ''.join(
return cElementTree.fromstring('<weblate>%s</weblate>' % text) ('<weblate>', strip_entities(text), '</weblate>')
)
if six.PY2:
text = text.encode('utf-8')
return cElementTree.fromstring(text)
def check_single(self, source, target, unit): def check_single(self, source, target, unit):
# Quick check if source looks like XML # Quick check if source looks like XML
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
Tests for quality checks. Tests for quality checks.
""" """
from __future__ import unicode_literals
from weblate.trans.checks.markup import ( from weblate.trans.checks.markup import (
BBCodeCheck, BBCodeCheck,
XMLTagsCheck, XMLTagsCheck,
...@@ -63,3 +64,6 @@ class XMLTagsCheckTest(CheckTestCase): ...@@ -63,3 +64,6 @@ class XMLTagsCheckTest(CheckTestCase):
(24, 28, '</b>'), (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