diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2009-03-01 20:11:07 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2009-03-01 20:11:07 +0000 |
commit | a0af60bef78801387b42663bd4a6138f1379d135 (patch) | |
tree | 688acee263f2b9d9764c4ae59b4a12a44b91afbc /bin/ksh/c_test.c | |
parent | 04b853ae83225adad2e406dc2d010366587ff73b (diff) |
Fix PR #723: test(1) operator precedence inconsistent with POSIX
Make sure ksh builtin test and test(1) do not differ.
From Christiano Farina Haesbaert. ok miod@
Diffstat (limited to 'bin/ksh/c_test.c')
-rw-r--r-- | bin/ksh/c_test.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/bin/ksh/c_test.c b/bin/ksh/c_test.c index 9e03fb0c3d3..33b2cf6a976 100644 --- a/bin/ksh/c_test.c +++ b/bin/ksh/c_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */ +/* $OpenBSD: c_test.c,v 1.18 2009/03/01 20:11:06 otto Exp $ */ /* * test(1); version 7-like -- author Erik Baalbergen @@ -457,15 +457,23 @@ test_primary(Test_env *te, int do_eval) } return res; } - if ((op = (Test_op) (*te->isa)(te, TM_UNOP))) { - /* unary expression */ - opnd1 = (*te->getopnd)(te, op, do_eval); - if (!opnd1) { - (*te->error)(te, -1, "missing argument"); - return 0; - } + /* + * Binary should have precedence over unary in this case + * so that something like test \( -f = -f \) is accepted + */ + if ((te->flags & TEF_DBRACKET) || (&te->pos.wp[1] < te->wp_end && + !test_isop(te, TM_BINOP, te->pos.wp[1]))) { + if ((op = (Test_op) (*te->isa)(te, TM_UNOP))) { + /* unary expression */ + opnd1 = (*te->getopnd)(te, op, do_eval); + if (!opnd1) { + (*te->error)(te, -1, "missing argument"); + return 0; + } - return (*te->eval)(te, op, opnd1, (const char *) 0, do_eval); + return (*te->eval)(te, op, opnd1, (const char *) 0, + do_eval); + } } opnd1 = (*te->getopnd)(te, TO_NONOP, do_eval); if (!opnd1) { |