Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1O17DM-0005TQ-0w for mharc-grub-devel@gnu.org; Sun, 11 Apr 2010 20:09:20 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O17DK-0005RV-Ah for grub-devel@gnu.org; Sun, 11 Apr 2010 20:09:18 -0400 Received: from [140.186.70.92] (port=57967 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O17DI-0005Oq-PZ for grub-devel@gnu.org; Sun, 11 Apr 2010 20:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O17DG-0004EJ-Sj for grub-devel@gnu.org; Sun, 11 Apr 2010 20:09:16 -0400 Received: from smarthost03.mail.zen.net.uk ([212.23.3.142]:51530) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O17DG-0004EA-HR for grub-devel@gnu.org; Sun, 11 Apr 2010 20:09:14 -0400 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost03.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1O17DE-0002bL-38; Mon, 12 Apr 2010 00:09:13 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) id 1O17D8-0000bv-00; Mon, 12 Apr 2010 01:09:06 +0100 Date: Mon, 12 Apr 2010 01:09:06 +0100 From: Colin Watson To: The development of GNU GRUB Message-ID: <20100412000906.GG11833@riva.ucam.org> References: <20100410211015.GA26131@pina.cat> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100410211015.GA26131@pina.cat> User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost03-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: marcos@softastur.org, malditoastur@gmail.com Subject: Re: escape strings in grub.cfg X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Apr 2010 00:09:18 -0000 On Sat, Apr 10, 2010 at 10:10:15PM +0100, Carles Pina i Estany wrote: > Last weekend, the Asturian team found a bug in Grub. Thanks for the > debugging. The string that appears in grub.cfg for "Loading the initram" > in Asturian is "Cargando'l discu RAM inicial...". So grub.cfg looks > like: > echo Cargando'l discu RAM inicial... > > This is syntactically invalid because the character "'". > > Easy work around: generate the line like: > echo "Cargando'l discu RAM inicial..." > > New problem: in some language, this string could have a double quote > inside. > > New solution: escape the double quotes strings when they are used in > gettext and always use these strings with double quotes. > > See the attached patch. > > I'm not convinced of the patch, does anybody has a cleaner idea/patch? This doesn't cover everything - you've just moved the goalposts a bit. Here's the relevant bit of the lexer: { \' { yy_pop_state (yyscanner); ARG (GRUB_SCRIPT_ARG_TYPE_SQSTR); } [^\']+ { COPY (yytext, yyleng); } } { \" { yy_pop_state (yyscanner); ARG (GRUB_SCRIPT_ARG_TYPE_DQSTR); } \$ { yy_push_state (VAR, yyscanner); ARG (GRUB_SCRIPT_ARG_TYPE_DQSTR); } \\\\ { COPY ("\\", 1); } \\\" { COPY ("\"", 1); } \\\n { /* ignore */ } [^\"$\\\n]+ { COPY (yytext, yyleng); } (.|\n) { COPY (yytext, yyleng); } } In other words, only ' is special (as a terminator) when reading a single-quoted string, and the sequences " $ \\ \" \n are special inside a double-quoted string. (Incidentally, I think there's another bug here; if $ is special, \$ should be special as well.) Given this, wouldn't you be better off using single-quotes instead? You'd then end up with: echo 'Cargando'\''l discu RAM inicial...' ... where the construction used to escape ' is "close quotes, literal ', reopen quotes". (Tested in grub-emu.) > +gettext_escape_double_quotes () > +{ > + echo -n $(gettext $@) | sed 's/\"/\\\"/' > +} This is underquoted, and in any case the 'echo -n' is redundant since gettext itself already writes to standard output and $() substitution strips trailing newlines. $@ requires special treatment, and that sed s/// command needs /g. With my suggestion, I'd recommend: gettext_quoted () { gettext "$@" | sed "s/'/'\\\\''/g" } ... and then make sure it's enclosed in '' rather than "" wherever it's used (or modify the sed to put single-quotes at the start and end, if that works out neater). -- Colin Watson [cjwatson@ubuntu.com]