]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: PO: Fix error when a --exclude-file option is present (regression 2023...
authorBruno Haible <bruno@clisp.org>
Sat, 27 Jul 2024 19:05:27 +0000 (21:05 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 27 Jul 2024 19:05:27 +0000 (21:05 +0200)
Reported by Nicolas Peugnet <n.peugnet@free.fr> via Santiago Vila
at <https://lists.gnu.org/archive/html/bug-gettext/2024-07/msg00030.html>.

* 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.

gettext-tools/src/x-po.c
gettext-tools/tests/Makefile.am
gettext-tools/tests/xgettext-po-5 [new file with mode: 0755]

index 740aa3d892b2689f031ccb3810e054d97eb429b9..a91564535788388e1fc5518c8d02b445585f02e9 100644 (file)
@@ -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 <millerp@canb.auug.org.au>
 
@@ -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,
index 004d914472447b13bc3928d58c507f309d1a9421..a6ca4f78f8af1f5268da4ecae466916a97bf02ee 100644 (file)
@@ -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 (executable)
index 0000000..c1cd40a
--- /dev/null
@@ -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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\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