itstool: Cherry-pick a couple of patches

This commit is contained in:
Joey Riches 2025-04-25 10:13:26 +01:00
parent c30628cecf
commit c0d5d73687
5 changed files with 118 additions and 3 deletions

View file

@ -0,0 +1,31 @@
Origin: https://github.com/itstool/itstool/pull/47
From: Harald van Dijk <harald@gigawatt.nl>
Date: Thu, 15 Jun 2023 23:18:11 +0100
Subject: Fix handling of untranslated nodes
If a translation is missing, get_translated returns the node it was
called with. But ph_node when passed to get_translated is part of
another document and cannot just be reparented, it needs to be cloned.
The reparenting leaves things in an inconsistent state where references
intended to refer to nodes in the original document no longer do so, and
they may then be accessed from those references after the new document
has already been freed.
Fixes bug #36.
---
itstool.in | 2 ++
1 file changed, 2 insertions(+)
diff --git a/itstool.in b/itstool.in
index c21ad4b..a948828 100755
--- a/itstool.in
+++ b/itstool.in
@@ -1096,6 +1096,8 @@ class Document (object):
child.replaceNode(newnode)
else:
repl = self.get_translated(ph_node, translations, strict=strict, lang=lang)
+ if repl == ph_node:
+ repl = repl.copyNode(1)
child.replaceNode(repl)
scan_node(child)
try:

View file

@ -0,0 +1,77 @@
From: Nils Philippsen <nils@tiptoe.de>
Date: Mon, 9 Oct 2023 14:26:43 +0200
Subject: [PATCH] Fix insufficiently quoted regular expressions
These went under the radar until Python 3.12 started warning about them.
Signed-off-by: Nils Philippsen <nils@tiptoe.de>
Origin: https://github.com/itstool/itstool/pull/51
Bug: https://github.com/itstool/itstool/issues/54
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/itstool/+bug/2061229
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1071634
---
itstool.in | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/itstool.in b/itstool.in
index 02904fa..f107e55 100755
--- a/itstool.in
+++ b/itstool.in
@@ -236,7 +236,7 @@ class Message (object):
if not isinstance(text, ustr_type):
text = ustr(text, 'utf-8')
self._message[-1] += text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
- if re.sub('\s+', ' ', text).strip() != '':
+ if re.sub(r'\s+', ' ', text).strip() != '':
self._empty = False
def add_entity_ref (self, name):
@@ -334,7 +334,7 @@ class Message (object):
message += '<_:%s-%i/>' % (msg.name, placeholder)
placeholder += 1
if not self._preserve:
- message = re.sub('\s+', ' ', message).strip()
+ message = re.sub(r'\s+', ' ', message).strip()
return message
def get_preserve_space (self):
@@ -472,9 +472,9 @@ class LocNote (object):
if self._preserve_space:
return self.locnote
else:
- return re.sub('\s+', ' ', self.locnote).strip()
+ return re.sub(r'\s+', ' ', self.locnote).strip()
elif self.locnoteref is not None:
- return '(itstool) link: ' + re.sub('\s+', ' ', self.locnoteref).strip()
+ return '(itstool) link: ' + re.sub(r'\s+', ' ', self.locnoteref).strip()
return ''
@@ -888,7 +888,7 @@ class Document (object):
trans = translations.ugettext('_\x04translator-credits')
if trans is None or trans == 'translator-credits':
return
- regex = re.compile('(.*) \<(.*)\>, (.*)')
+ regex = re.compile(r'(.*) \<(.*)\>, (.*)')
for credit in trans.split('\n'):
match = regex.match(credit)
if not match:
@@ -923,7 +923,7 @@ class Document (object):
prevnode = None
if node.prev is not None and node.prev.type == 'text':
prevtext = node.prev.content
- if re.sub('\s+', '', prevtext) == '':
+ if re.sub(r'\s+', '', prevtext) == '':
prevnode = node.prev
for lang in sorted(list(translations.keys()), reverse=True):
locale = self.get_its_locale_filter(node)
@@ -1449,7 +1449,7 @@ def match_locale(extrange, locale):
localei += 1
return True
-_locale_pattern = re.compile('([a-zA-Z0-9-]+)(_[A-Za-z0-9]+)?(@[A-Za-z0-9]+)?(\.[A-Za-z0-9]+)?')
+_locale_pattern = re.compile(r'([a-zA-Z0-9-]+)(_[A-Za-z0-9]+)?(@[A-Za-z0-9]+)?(\.[A-Za-z0-9]+)?')
def convert_locale (locale):
# Automatically convert POSIX-style locales to BCP47
match = _locale_pattern.match(locale)

View file

@ -0,0 +1,5 @@
releases:
id: 13109
rss: https://github.com/itstool/itstool/releases.atom
security:
cpe: ~ # Last checked 2025-04-25

View file

@ -1,6 +1,6 @@
name : itstool
version : 2.0.7
release : 10
release : 11
source :
- https://github.com/itstool/itstool/archive/2.0.7.tar.gz : fba78a37dc3535e4686c7f57407b97d03c676e3a57beac5fb2315162b0cc3176
homepage : http://itstool.org/
@ -17,6 +17,8 @@ environment: |
export PYTHON=/usr/bin/python3
setup : |
%patch -p1 -i $pkgfiles/itstool-2.0.5-fix-crash-wrong-encoding.patch
%patch -p1 -i $pkgfiles/fix-handling-untranslated-nodes.patch
%patch -p1 -i $pkgfiles/regex-insufficent-quoting.patch
%reconfigure
build : |
%make

View file

@ -31,8 +31,8 @@
</Files>
</Package>
<History>
<Update release="10">
<Date>2024-02-15</Date>
<Update release="11">
<Date>2025-04-25</Date>
<Version>2.0.7</Version>
<Comment>Packaging update</Comment>
<Name>Joey Riches</Name>