itstool-2.0.5-fix_crash_pipe.patch (6019B)
- https://git.ortolo.eu/pkg-itstool.git/patch/?h=contrib/fix_crash_pipe&id=7e737993e1320b0a7ea82618cb8031e93d8b2e80&id2=39000db89b4d376af34fd4499743ac0fa5d7cd90
- From 95fd7ad4a7575639f17439832fcd406d94402322 Mon Sep 17 00:00:00 2001
- From: Tanguy Ortolo <tanguy+debian@ortolo.eu>
- Date: Fri, 7 Dec 2018 14:22:09 +0100
- Subject: Fix a unicode decode issue
- Since the support of Python 3, ITS Tool crashes with some documentation,
- namely Gnumeric's.
- This comes from the reporting of a merge error (which happens to come
- from invalid XML markup in a translation, which is an issue but should
- not lead to a crash). The error is reported by writing a
- percent-formatted unicode message, with one percent-parameter being the
- original msgstr, which is a unicode string too. The msgstr was
- needlessly encoded to bytes with utf-8, and then automatically decoded
- back to unicode by Python, using the default ascii code, which fails and
- raises an unexpected exception if it contains anything out of ASCII.
- This fixes the issue by removing the needless encode('utf-8').
- ---
- itstool.in | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
- diff --git a/itstool.in b/itstool.in
- index b3c0033..ac7d7d2 100755
- --- a/itstool.in
- +++ b/itstool.in
- @@ -1062,7 +1062,7 @@ class Document (object):
- else:
- sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
- (lang + ' ') if lang is not None else '',
- - msgstr.encode('utf-8')))
- + msgstr))
- self._xml_err = ''
- return node
- def scan_node(node):
- @@ -1089,7 +1089,7 @@ class Document (object):
- else:
- sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
- (lang + ' ') if lang is not None else '',
- - msgstr.encode('utf-8')))
- + msgstr))
- self._xml_err = ''
- ctxt.doc().freeDoc()
- return node
- --
- cgit v1.1
- From 7eb912264997067993ed0c2b4e74790bab57abe8 Mon Sep 17 00:00:00 2001
- From: Tanguy Ortolo <tanguy+debian@ortolo.eu>
- Date: Sun, 10 Mar 2019 15:22:27 +0100
- Subject: Fix a further similar crash
- ---
- itstool.in | 21 +++++++++++++++++----
- 1 file changed, 17 insertions(+), 4 deletions(-)
- diff --git a/itstool.in b/itstool.in
- index ac7d7d2..5b0051f 100755
- --- a/itstool.in
- +++ b/itstool.in
- @@ -44,9 +44,22 @@ if PY3:
- else:
- return str(s)
- ustr_type = str
- + def pr_str(s):
- + """Return a string that can be safely print()ed"""
- + # Since print works on both bytes and unicode, just return the argument
- + return s
- else:
- string_types = basestring,
- ustr = ustr_type = unicode
- + def pr_str(s):
- + """Return a string that can be safely print()ed"""
- + if isinstance(s, str):
- + # Since print works on str, just return the argument
- + return s
- + else:
- + # print may not work on unicode if the output encoding cannot be
- + # detected, so just encode with UTF-8
- + return unicode.encode(s, 'utf-8')
- NS_ITS = 'http://www.w3.org/2005/11/its'
- NS_ITST = 'http://itstool.org/extensions/'
- @@ -1060,9 +1073,9 @@ class Document (object):
- if strict:
- raise
- else:
- - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
- + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
- (lang + ' ') if lang is not None else '',
- - msgstr))
- + msgstr)))
- self._xml_err = ''
- return node
- def scan_node(node):
- @@ -1087,9 +1100,9 @@ class Document (object):
- if strict:
- raise
- else:
- - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
- + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
- (lang + ' ') if lang is not None else '',
- - msgstr))
- + msgstr)))
- self._xml_err = ''
- ctxt.doc().freeDoc()
- return node
- --
- cgit v1.1
- From 7e737993e1320b0a7ea82618cb8031e93d8b2e80 Mon Sep 17 00:00:00 2001
- From: Tanguy Ortolo <tanguy+debian@ortolo.eu>
- Date: Sun, 10 Mar 2019 15:27:25 +0100
- Subject: Fix an encoding crash when redirected to a pipe
- ITS Tool crashes when output is redirected to a pipe. This comes from
- Python not knowing the preferred encoding for stdout, and using ASCII by
- default, therefore failing to encode anything outside of it.
- This patch makes ITS Tool write to an UTF-8 encoding wrapper around
- stdout.
- ---
- itstool.in | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
- diff --git a/itstool.in b/itstool.in
- index 5b0051f..592dc77 100755
- --- a/itstool.in
- +++ b/itstool.in
- @@ -48,6 +48,7 @@ if PY3:
- """Return a string that can be safely print()ed"""
- # Since print works on both bytes and unicode, just return the argument
- return s
- + uout = sys.stdout
- else:
- string_types = basestring,
- ustr = ustr_type = unicode
- @@ -60,6 +61,8 @@ else:
- # print may not work on unicode if the output encoding cannot be
- # detected, so just encode with UTF-8
- return unicode.encode(s, 'utf-8')
- + import codecs
- + uout = codecs.getwriter('utf-8')(sys.stdout)
- NS_ITS = 'http://www.w3.org/2005/11/its'
- NS_ITST = 'http://itstool.org/extensions/'
- @@ -1565,7 +1568,7 @@ if __name__ == '__main__':
- if opts.test is None:
- doc.generate_messages()
- if opts.output is None or opts.output == '-':
- - out = sys.stdout
- + out = uout
- else:
- try:
- out = io.open(opts.output, 'wt', encoding='utf-8')
- --
- cgit v1.1