summaryrefslogtreecommitdiff
path: root/system/pdksh/patches/112_OpenBSD-test.patch
blob: 7058a2dac8416af6f9249fe2cc09882dfe18f574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From OpenBSD:

2009-03-01 21:11  otto

        * c_test.c (1.18): 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@


Index: pdksh-5.2.14/c_test.c
===================================================================
--- pdksh-5.2.14.orig/c_test.c	2009-09-19 11:22:39.000000000 +0200
+++ pdksh-5.2.14/c_test.c	2009-09-19 12:03:25.000000000 +0200
@@ -551,15 +551,23 @@
 		}
 		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) {
Index: pdksh-5.2.14/tests/debian-112.t
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ pdksh-5.2.14/tests/debian-112.t	2009-09-19 12:06:33.000000000 +0200
@@ -0,0 +1,8 @@
+name: debian-112-1
+description:
+	Check test operator precedence
+stdin:
+	test \( -f = -f \) && echo OK
+expected-stdout:
+	OK
+---