From 132f9f91a87e313d3702aaa3ac85bdf060207564 Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 6 Jul 2015 21:52:45 +0000 Subject: [PATCH] Fix parsing of if statement with a missing space after the if closing parenthesis (Fridolin Pokorny) --- Fixes | 1 + Makefile.in | 4 ++-- sh.func.c | 11 +++++++++ tests/parenthesis.at | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tests/parenthesis.at diff --git a/Fixes b/Fixes index aa779b1..07afe71 100644 --- a/Fixes +++ b/Fixes @@ -1,3 +1,4 @@ + 3. Fix parsing of 'if (cond)then' (Fridolin Pokorny) 2. PR/437: Fix handling of invalid unicode characters. 1. PR/451: Fix error messages containing %c to be always '%c' diff --git a/Makefile.in b/Makefile.in index bfe51b6..6d1f964 100644 --- a/Makefile.in +++ b/Makefile.in @@ -415,8 +415,8 @@ AVSRCS= Fixes MAKEDIFFS MAKESHAR NewThings README FAQ \ tests/testsuite.at aclocal.m4 TESTFILES= tests/aliases.at tests/arguments.at tests/commands.at \ tests/expr.at tests/lexical.at tests/mb-eucjp.at \ - tests/mb-utf8.at tests/noexec.at tests/syntax.at tests/subst.at \ - tests/variables.at tests/sh.dol.at + tests/mb-utf8.at tests/noexec.at tests/parenthesis.at tests/syntax.at \ + tests/subst.at tests/variables.at tests/sh.dol.at VHSRCS=${PVSRCS} ${AVSRCS} diff --git a/sh.func.c b/sh.func.c index 7b70760..bb670b8 100644 --- a/sh.func.c +++ b/sh.func.c @@ -1045,6 +1045,17 @@ getword(struct Strbuf *wp) goto past; if (wp) Strbuf_append1(wp, (Char) c); + if (!d && c == ')') { + if (!first && wp) { + goto past_word_end; + } else { + if (wp) { + wp->len = 1; + Strbuf_terminate(wp); + } + return found; + } + } if (!first && !d && c == '(') { if (wp) goto past_word_end; diff --git a/tests/parenthesis.at b/tests/parenthesis.at new file mode 100644 index 0000000..2832b50 --- /dev/null +++ b/tests/parenthesis.at @@ -0,0 +1,63 @@ +# Parenthesis handling + +AT_SETUP([Parenthesis no space]) +AT_DATA([no-space.csh], +[[ +if(1 == 1) then + echo 1 +else + if (2 == 22 )then + echo 2 + endif + echo 3 +endif +]]) +AT_CHECK([tcsh -f < no-space.csh], ,[1 +]) + +AT_CLEANUP + +AT_SETUP([Parenthesis space]) +AT_DATA([space.csh], +[[ +if (1 == 1) then + echo 1 +else + if (2 == 22 ) then + echo 2 + endif + echo 3 +endif +]]) +AT_CHECK([tcsh -f < space.csh], ,[1 +]) + +AT_CLEANUP + +AT_SETUP([Parenthesis space escaped]) +AT_DATA([space-escaped.csh], +[[ +if (1 == 1) then + echo 1 +else + if (2 == 22 )\ then + echo 2 + endif + echo 3 +endif +]]) +AT_CHECK([tcsh -f < space-escaped.csh], ,[1 +]) +AT_CLEANUP + +AT_SETUP([Parenthesis escaped]) +AT_DATA([parenthesis-escaped.csh], +[[ +if ( ')' == \) ) then + echo 1 +endif +]]) +AT_CHECK([tcsh -f < parenthesis-escaped.csh], ,[1 +]) +AT_CLEANUP + diff --git a/tests/testsuite.at b/tests/testsuite.at index fd1d7b9..d358a7f 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -18,6 +18,7 @@ m4_include([expr.at]) m4_include([lexical.at]) m4_include([mb-eucjp.at]) m4_include([mb-utf8.at]) +m4_include([parenthesis.at]) m4_include([subst.at]) m4_include([syntax.at]) m4_include([variables.at]) -- 2.5.5