From 758bb619e8631be1773cbecb4226580c83a41651 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 29 Jul 2017 21:09:30 -0400 Subject: exec: Fix more corner cases with -ok ... + -ok should look for a ; even if it sees {} +, according to POSIX. --- exec.c | 19 ++++++++++--------- tests.sh | 10 ++++++++++ tests/test_ok_plus_semicolon.out | 19 +++++++++++++++++++ tests/test_okdir_plus_semicolon.out | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 tests/test_ok_plus_semicolon.out create mode 100644 tests/test_okdir_plus_semicolon.out diff --git a/exec.c b/exec.c index 250bba7..42deccf 100644 --- a/exec.c +++ b/exec.c @@ -127,21 +127,22 @@ struct bfs_exec *parse_bfs_exec(char **argv, enum bfs_exec_flags flags, const st for (i = 1; ; ++i) { const char *arg = argv[i]; if (!arg) { - cfprintf(cerr, "%{er}error: %s: Expected ';' or '+'.%{rs}\n", argv[0]); + if (execbuf->flags & BFS_EXEC_CONFIRM) { + cfprintf(cerr, "%{er}error: %s: Expected '... ;'.%{rs}\n", argv[0]); + } else { + cfprintf(cerr, "%{er}error: %s: Expected '... ;' or '... {} +'.%{rs}\n", argv[0]); + } goto fail; } else if (strcmp(arg, ";") == 0) { break; - } else if (strcmp(arg, "+") == 0 && strcmp(argv[i - 1], "{}") == 0) { - execbuf->flags |= BFS_EXEC_MULTI; - break; + } else if (strcmp(arg, "+") == 0) { + if (!(execbuf->flags & BFS_EXEC_CONFIRM) && strcmp(argv[i - 1], "{}") == 0) { + execbuf->flags |= BFS_EXEC_MULTI; + break; + } } } - if ((execbuf->flags & BFS_EXEC_CONFIRM) && (execbuf->flags & BFS_EXEC_MULTI)) { - cfprintf(cerr, "%{er}error: %s ... + is not supported.%{rs}\n", argv[0]); - goto fail; - } - execbuf->tmpl_argv = argv + 1; execbuf->tmpl_argc = i - 1; diff --git a/tests.sh b/tests.sh index 3da8d5e..cf9e1a3 100755 --- a/tests.sh +++ b/tests.sh @@ -198,6 +198,7 @@ posix_tests=( test_perm_leading_plus_symbolic_minus test_permcopy test_ok_stdin + test_ok_plus_semicolon test_parens test_bang test_implicit_and @@ -307,6 +308,7 @@ gnu_tests=( test_execdir_slash test_execdir_slash_pwd test_execdir_slashes + test_okdir_plus_semicolon test_weird_names test_flag_weird_names test_follow_comma @@ -967,6 +969,14 @@ function test_okdir_stdin() { yes | bfs_diff basic -okdir bash -c "printf '%s? ' {} && head -n1" \; 2>/dev/null } +function test_ok_plus_semicolon() { + yes | bfs_diff basic -ok echo '{}' + \; 2>/dev/null +} + +function test_okdir_plus_semicolon() { + yes | bfs_diff basic -okdir echo '{}' + \; 2>/dev/null +} + function test_delete() { rm -rf scratch/* touchp scratch/foo/bar/baz diff --git a/tests/test_ok_plus_semicolon.out b/tests/test_ok_plus_semicolon.out new file mode 100644 index 0000000..85d27e5 --- /dev/null +++ b/tests/test_ok_plus_semicolon.out @@ -0,0 +1,19 @@ +basic + +basic/a + +basic/b + +basic/c + +basic/e + +basic/g + +basic/i + +basic/j + +basic/k + +basic/l + +basic/c/d + +basic/e/f + +basic/g/h + +basic/j/foo + +basic/k/foo + +basic/l/foo + +basic/k/foo/bar + +basic/l/foo/bar + +basic/l/foo/bar/baz + diff --git a/tests/test_okdir_plus_semicolon.out b/tests/test_okdir_plus_semicolon.out new file mode 100644 index 0000000..1909d27 --- /dev/null +++ b/tests/test_okdir_plus_semicolon.out @@ -0,0 +1,19 @@ +./a + +./b + +./bar + +./bar + +./basic + +./baz + +./c + +./d + +./e + +./f + +./foo + +./foo + +./foo + +./g + +./h + +./i + +./j + +./k + +./l + -- cgit v1.2.3