From: Bruno Haible Date: Sun, 18 Aug 2019 23:34:34 +0000 (+0200) Subject: xgettext: Fix parsing of escaped single-quote characters in shell parser. X-Git-Tag: v0.20.2~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39072866b27c2549c9b3e9e237ff80df5d296526;p=thirdparty%2Fgettext.git xgettext: Fix parsing of escaped single-quote characters in shell parser. Reported by Markus Gothe at . * 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. --- diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 0cf542efd..dcfd7895a 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -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); } diff --git a/gettext-tools/tests/xgettext-sh-1 b/gettext-tools/tests/xgettext-sh-1 index ea2493103..4ace9a360 100755 --- a/gettext-tools/tests/xgettext-sh-1 +++ b/gettext-tools/tests/xgettext-sh-1 @@ -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 ;