]> git.pld-linux.org Git - packages/itstool.git/blob - itstool-fix-crash-wrong-encoding.patch
- added fix-crash-wrong-encoding patch from Fedora; release 2
[packages/itstool.git] / itstool-fix-crash-wrong-encoding.patch
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
7  out of ascii.
8  .
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
17
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
22 @@ -44,9 +44,22 @@
23          else:
24              return str(s)
25      ustr_type = str
26 +    def pr_str(s):
27 +        """Return a string that can be safely print()ed"""
28 +        # Since print works on both bytes and unicode, just return the argument
29 +        return s
30  else:
31      string_types = basestring,
32      ustr = ustr_type = unicode
33 +    def pr_str(s):
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
37 +            return s
38 +        else:
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')
42  
43  NS_ITS = 'http://www.w3.org/2005/11/its'
44  NS_ITST = 'http://itstool.org/extensions/'
45 @@ -1060,9 +1073,9 @@
46              if strict:
47                  raise
48              else:
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')))
53 +                        msgstr)))
54                  self._xml_err = ''
55                  return node
56          def scan_node(node):
57 @@ -1087,9 +1100,9 @@
58              if strict:
59                  raise
60              else:
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')))
65 +                    msgstr)))
66                  self._xml_err = ''
67                  ctxt.doc().freeDoc()
68                  return node
This page took 0.075563 seconds and 3 git commands to generate.