logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

itstool-2.0.5-fix_crash_pipe.patch (6019B)


  1. https://git.ortolo.eu/pkg-itstool.git/patch/?h=contrib/fix_crash_pipe&id=7e737993e1320b0a7ea82618cb8031e93d8b2e80&id2=39000db89b4d376af34fd4499743ac0fa5d7cd90
  2. From 95fd7ad4a7575639f17439832fcd406d94402322 Mon Sep 17 00:00:00 2001
  3. From: Tanguy Ortolo <tanguy+debian@ortolo.eu>
  4. Date: Fri, 7 Dec 2018 14:22:09 +0100
  5. Subject: Fix a unicode decode issue
  6. Since the support of Python 3, ITS Tool crashes with some documentation,
  7. namely Gnumeric's.
  8. This comes from the reporting of a merge error (which happens to come
  9. from invalid XML markup in a translation, which is an issue but should
  10. not lead to a crash). The error is reported by writing a
  11. percent-formatted unicode message, with one percent-parameter being the
  12. original msgstr, which is a unicode string too. The msgstr was
  13. needlessly encoded to bytes with utf-8, and then automatically decoded
  14. back to unicode by Python, using the default ascii code, which fails and
  15. raises an unexpected exception if it contains anything out of ASCII.
  16. This fixes the issue by removing the needless encode('utf-8').
  17. ---
  18. itstool.in | 4 ++--
  19. 1 file changed, 2 insertions(+), 2 deletions(-)
  20. diff --git a/itstool.in b/itstool.in
  21. index b3c0033..ac7d7d2 100755
  22. --- a/itstool.in
  23. +++ b/itstool.in
  24. @@ -1062,7 +1062,7 @@ class Document (object):
  25. else:
  26. sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
  27. (lang + ' ') if lang is not None else '',
  28. - msgstr.encode('utf-8')))
  29. + msgstr))
  30. self._xml_err = ''
  31. return node
  32. def scan_node(node):
  33. @@ -1089,7 +1089,7 @@ class Document (object):
  34. else:
  35. sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
  36. (lang + ' ') if lang is not None else '',
  37. - msgstr.encode('utf-8')))
  38. + msgstr))
  39. self._xml_err = ''
  40. ctxt.doc().freeDoc()
  41. return node
  42. --
  43. cgit v1.1
  44. From 7eb912264997067993ed0c2b4e74790bab57abe8 Mon Sep 17 00:00:00 2001
  45. From: Tanguy Ortolo <tanguy+debian@ortolo.eu>
  46. Date: Sun, 10 Mar 2019 15:22:27 +0100
  47. Subject: Fix a further similar crash
  48. ---
  49. itstool.in | 21 +++++++++++++++++----
  50. 1 file changed, 17 insertions(+), 4 deletions(-)
  51. diff --git a/itstool.in b/itstool.in
  52. index ac7d7d2..5b0051f 100755
  53. --- a/itstool.in
  54. +++ b/itstool.in
  55. @@ -44,9 +44,22 @@ if PY3:
  56. else:
  57. return str(s)
  58. ustr_type = str
  59. + def pr_str(s):
  60. + """Return a string that can be safely print()ed"""
  61. + # Since print works on both bytes and unicode, just return the argument
  62. + return s
  63. else:
  64. string_types = basestring,
  65. ustr = ustr_type = unicode
  66. + def pr_str(s):
  67. + """Return a string that can be safely print()ed"""
  68. + if isinstance(s, str):
  69. + # Since print works on str, just return the argument
  70. + return s
  71. + else:
  72. + # print may not work on unicode if the output encoding cannot be
  73. + # detected, so just encode with UTF-8
  74. + return unicode.encode(s, 'utf-8')
  75. NS_ITS = 'http://www.w3.org/2005/11/its'
  76. NS_ITST = 'http://itstool.org/extensions/'
  77. @@ -1060,9 +1073,9 @@ class Document (object):
  78. if strict:
  79. raise
  80. else:
  81. - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
  82. + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
  83. (lang + ' ') if lang is not None else '',
  84. - msgstr))
  85. + msgstr)))
  86. self._xml_err = ''
  87. return node
  88. def scan_node(node):
  89. @@ -1087,9 +1100,9 @@ class Document (object):
  90. if strict:
  91. raise
  92. else:
  93. - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
  94. + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
  95. (lang + ' ') if lang is not None else '',
  96. - msgstr))
  97. + msgstr)))
  98. self._xml_err = ''
  99. ctxt.doc().freeDoc()
  100. return node
  101. --
  102. cgit v1.1
  103. From 7e737993e1320b0a7ea82618cb8031e93d8b2e80 Mon Sep 17 00:00:00 2001
  104. From: Tanguy Ortolo <tanguy+debian@ortolo.eu>
  105. Date: Sun, 10 Mar 2019 15:27:25 +0100
  106. Subject: Fix an encoding crash when redirected to a pipe
  107. ITS Tool crashes when output is redirected to a pipe. This comes from
  108. Python not knowing the preferred encoding for stdout, and using ASCII by
  109. default, therefore failing to encode anything outside of it.
  110. This patch makes ITS Tool write to an UTF-8 encoding wrapper around
  111. stdout.
  112. ---
  113. itstool.in | 5 ++++-
  114. 1 file changed, 4 insertions(+), 1 deletion(-)
  115. diff --git a/itstool.in b/itstool.in
  116. index 5b0051f..592dc77 100755
  117. --- a/itstool.in
  118. +++ b/itstool.in
  119. @@ -48,6 +48,7 @@ if PY3:
  120. """Return a string that can be safely print()ed"""
  121. # Since print works on both bytes and unicode, just return the argument
  122. return s
  123. + uout = sys.stdout
  124. else:
  125. string_types = basestring,
  126. ustr = ustr_type = unicode
  127. @@ -60,6 +61,8 @@ else:
  128. # print may not work on unicode if the output encoding cannot be
  129. # detected, so just encode with UTF-8
  130. return unicode.encode(s, 'utf-8')
  131. + import codecs
  132. + uout = codecs.getwriter('utf-8')(sys.stdout)
  133. NS_ITS = 'http://www.w3.org/2005/11/its'
  134. NS_ITST = 'http://itstool.org/extensions/'
  135. @@ -1565,7 +1568,7 @@ if __name__ == '__main__':
  136. if opts.test is None:
  137. doc.generate_messages()
  138. if opts.output is None or opts.output == '-':
  139. - out = sys.stdout
  140. + out = uout
  141. else:
  142. try:
  143. out = io.open(opts.output, 'wt', encoding='utf-8')
  144. --
  145. cgit v1.1