]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Fix parsing of escaped single-quote characters in shell parser.
authorBruno Haible <bruno@clisp.org>
Sun, 18 Aug 2019 23:34:34 +0000 (01:34 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Apr 2020 11:06:39 +0000 (13:06 +0200)
Reported by Markus Gothe <nietzsche@lysator.liu.se>
at <https://savannah.gnu.org/bugs/?49809>.

* gettext-tools/src/x-sh.c (phase2_getc): Handle the case c == '\''
&& !open_singlequote && !open_doublequote differently.
* gettext-tools/tests/xgettext-sh-1: Add test with an escape single-quote.

gettext-tools/src/x-sh.c
gettext-tools/tests/xgettext-sh-1

index 0cf542efd35daa9fae62e01116edc457d3c27b37..dcfd7895a1dd7e97737bef01e58f5eca35aa9f36 100644 (file)
@@ -599,7 +599,7 @@ phase2_getc ()
       /* The count of backslashes is > 0 and < expected_count, therefore the
          result depends on c, the first character after the backslashes.
          Note: The formulas below don't necessarily have a logic; they were
-         empirically determined such that 1. the xgettext-30 test succeeds,
+         empirically determined such that 1. the xgettext-sh-1 test succeeds,
          2. the behaviour for count == 0 would correspond to the one without
          any baskslash.  */
       if (c == '\'')
@@ -611,7 +611,9 @@ phase2_getc ()
             }
           else
             return ((open_doublequote
-                     || (open_singlequote && open_singlequote_terminator != c))
+                     || (open_singlequote
+                         ? open_singlequote_terminator != c
+                         : count == (expected_count >> 1)))
                     ? QUOTED (c)
                     : c);
         }
index ea249310307b24384c1bc7bfd452ac4091ee37f6..4ace9a3602411f4e938e79550c03d6917a7fc0a4 100755 (executable)
@@ -308,6 +308,10 @@ echo "`echo "\`gettext 'depth_2_11_squote_6_\\\\\\$var'\`"`"
 echo "`echo "\`gettext 'depth_2_11_squote_7_\\\\\\\$var'\`"`"
 echo "`echo "\`gettext 'depth_2_11_squote_8_\\\\\\\\$var'\`"`"
 
+# Test backslash before single-quote.
+
+echo \'
+
 # Test backslash before semicolon.
 
 ngettext  depth_0_none_0_semi ;