Module Name:    src
Committed By:   rillig
Date:           Sat Mar 15 14:33:39 UTC 2025

Modified Files:
        src/bin/expr: expr.y
        src/tests/bin/expr: t_expr.sh

Log Message:
expr: only skip '--' once


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/bin/expr/expr.y
cvs rdiff -u -r1.11 -r1.12 src/tests/bin/expr/t_expr.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.51 src/bin/expr/expr.y:1.52
--- src/bin/expr/expr.y:1.51	Sat Mar 15 14:26:16 2025
+++ src/bin/expr/expr.y	Sat Mar 15 14:33:39 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.51 2025/03/15 14:26:16 rillig Exp $ */
+/* $NetBSD: expr.y,v 1.52 2025/03/15 14:33:39 rillig Exp $ */
 
 /*-
  * Copyright (c) 2000, 2025 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 %{
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: expr.y,v 1.51 2025/03/15 14:26:16 rillig Exp $");
+__RCSID("$NetBSD: expr.y,v 1.52 2025/03/15 14:33:39 rillig Exp $");
 
 #include <sys/types.h>
 
@@ -335,6 +335,7 @@ yylex(void)
 		    && (p[0] == '>' || p[0] == '<' || p[0] == '!'))
 		retval = COMPARE;
 	else if (handle_ddash && strcmp(p, "--") == 0) {
+		handle_ddash = 0;
 		retval = yylex();
 		if (retval != STRING && retval != LPAREN && retval != RPAREN) {
 			retval = STRING;

Index: src/tests/bin/expr/t_expr.sh
diff -u src/tests/bin/expr/t_expr.sh:1.11 src/tests/bin/expr/t_expr.sh:1.12
--- src/tests/bin/expr/t_expr.sh:1.11	Sat Mar 15 10:31:28 2025
+++ src/tests/bin/expr/t_expr.sh	Sat Mar 15 14:33:39 2025
@@ -1,4 +1,4 @@
-# $NetBSD: t_expr.sh,v 1.11 2025/03/15 10:31:28 rillig Exp $
+# $NetBSD: t_expr.sh,v 1.12 2025/03/15 14:33:39 rillig Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -25,6 +25,8 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
+: "${expr_prog:=expr}"
+
 # usage: test_expr operand ... result|error
 test_expr() {
 	i=1
@@ -36,7 +38,7 @@ test_expr() {
 	shift
 
 	# shellcheck disable=SC2003
-	actual=$(expr "$@" 2>&1 || :)
+	actual=$("$expr_prog" "$@" 2>&1 || :)
 
 	printf "%s => '%s'\n" "$*" "$expected" >> expected
 	printf "%s => '%s'\n" "$*" "$actual" >> actual
@@ -172,6 +174,9 @@ basic_functional_body() {
 	test_expr 2 '2'
 	test_expr -4 '-4'
 	test_expr hello 'hello'
+	test_expr -- double-dash 'double-dash'
+	test_expr -- -- -- six-dashes 'expr: syntax error'
+	test_expr 3 -- + 4 'expr: syntax error'
 
 	test_finish
 }

Reply via email to