1 Description: Fix the crash from #912099
2 ITS Tool 2.0.4 crashes when building some documentation, as reported in
3 #912099. This comes from translations with invalid XML markup, which ITS Tool
4 fails to merge (which is not abnormal), and to report these issues, needlessly
5 encodes the original msgstr from unicode to bytes, causing it to be recoded
6 using the default ascii codec, which fails when the msgstr contains anything
9 This patch removes the useless decoding, avoiding the failing subsequent
10 recoding. It also explicitly encodes the output strings to be able to print
11 them in all cases, even when the output encoding cannot be detected.
12 Bug: https://github.com/itstool/itstool/issues/25
13 Bug-Debian: https://bugs.debian.org/912099
14 Forwarded: https://github.com/itstool/itstool/issues/25
15 Author: Tanguy Ortolo <tanguy+debian@ortolo.eu>
16 Last-Update: 2018-12-071
18 Index: itstool/itstool.in
19 ===================================================================
20 --- itstool.orig/itstool.in 2018-12-10 18:31:23.762143539 +0100
21 +++ itstool/itstool.in 2018-12-10 18:38:03.496777117 +0100
27 + """Return a string that can be safely print()ed"""
28 + # Since print works on both bytes and unicode, just return the argument
31 string_types = basestring,
32 ustr = ustr_type = unicode
34 + """Return a string that can be safely print()ed"""
35 + if isinstance(s, str):
36 + # Since print works on str, just return the argument
39 + # print may not work on unicode if the output encoding cannot be
40 + # detected, so just encode with UTF-8
41 + return unicode.encode(s, 'utf-8')
43 NS_ITS = 'http://www.w3.org/2005/11/its'
44 NS_ITST = 'http://itstool.org/extensions/'
49 - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
50 + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
51 (lang + ' ') if lang is not None else '',
52 - msgstr.encode('utf-8')))
61 - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
62 + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
63 (lang + ' ') if lang is not None else '',
64 - msgstr.encode('utf-8')))