From: Bruno Haible Date: Sat, 27 Jul 2024 19:05:27 +0000 (+0200) Subject: xgettext: PO: Fix error when a --exclude-file option is present (regression 2023... X-Git-Tag: v0.23~220 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d64216aecaf15883c944539657562127b10d0e1a;p=thirdparty%2Fgettext.git xgettext: PO: Fix error when a --exclude-file option is present (regression 2023-03-10). Reported by Nicolas Peugnet via Santiago Vila at . * gettext-tools/src/x-po.c (extract_add_message): If the message is the header entry and is among the messages to exclude, save the header charset from it before discarding it. * gettext-tools/tests/xgettext-po-5: New file, based on gettext-tools/tests/xgettext-po-3. * gettext-tools/tests/Makefile.am (TESTS): Add it. --- diff --git a/gettext-tools/src/x-po.c b/gettext-tools/src/x-po.c index 740aa3d89..a91564535 100644 --- a/gettext-tools/src/x-po.c +++ b/gettext-tools/src/x-po.c @@ -1,5 +1,5 @@ /* xgettext PO, JavaProperties, and NXStringTable backends. - Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009, 2014, 2018, 2020, 2023 Free Software Foundation, Inc. + Copyright (C) 1995-2024 Free Software Foundation, Inc. This file was written by Peter Miller @@ -65,10 +65,6 @@ extract_add_message (default_catalog_reader_ty *this, char *prev_msgid_plural, bool force_fuzzy, bool obsolete) { - /* See whether we shall exclude this message. */ - if (exclude != NULL && message_list_search (exclude, msgctxt, msgid) != NULL) - goto discard; - /* If the msgid is the empty string, it is the old header. Throw it away, we have constructed a new one. Only remember its charset. But if no new one was constructed, keep the old header. This is useful @@ -111,6 +107,10 @@ extract_add_message (default_catalog_reader_ty *this, return; } + /* See whether we shall exclude this message. */ + if (exclude != NULL && message_list_search (exclude, msgctxt, msgid) != NULL) + goto discard; + /* Invoke superclass method. */ default_add_message (this, msgctxt, msgid, msgid_pos, msgid_plural, msgstr, msgstr_len, msgstr_pos, diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 004d91447..a6ca4f78f 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -141,7 +141,7 @@ TESTS = gettext-1 gettext-2 \ xgettext-php-5 \ xgettext-php-stackovfl-1 xgettext-php-stackovfl-2 \ xgettext-php-stackovfl-3 xgettext-php-stackovfl-4 \ - xgettext-po-1 xgettext-po-2 xgettext-po-3 xgettext-po-4 \ + xgettext-po-1 xgettext-po-2 xgettext-po-3 xgettext-po-4 xgettext-po-5 \ xgettext-properties-1 xgettext-properties-2 xgettext-properties-3 \ xgettext-properties-4 \ xgettext-rst-1 xgettext-rst-2 \ diff --git a/gettext-tools/tests/xgettext-po-5 b/gettext-tools/tests/xgettext-po-5 new file mode 100755 index 000000000..c1cd40a72 --- /dev/null +++ b/gettext-tools/tests/xgettext-po-5 @@ -0,0 +1,49 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test PO extractor with non-ASCII input file with header entry and +# --exclude-file option. + +cat <<\EOF > xg-po-5.exclusions +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "no" +msgstr "" +EOF + +: ${XGETTEXT=xgettext} +${XGETTEXT} --no-location -d xg-po-5.tmp --exclude-file xg-po-5.exclusions \ + "$wabs_srcdir"/testdata/xg-po-3.po \ + || Exit 1 +func_filter_POT_Creation_Date xg-po-5.tmp.po xg-po-5.pot + +cat <<\EOF > xg-po-5.ok +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "ü" +msgstr "" +EOF + +: ${DIFF=diff} +${DIFF} xg-po-5.ok xg-po-5.pot || Exit 1 + +Exit 0