From cdb96f1a6ab4b8bbcca35c48cd8c232e50c04390 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 21 Apr 2019 17:03:29 -0400 Subject: parse: Allow things like -uid ++10 GNU find does too. --- parse.c | 12 +++++++++--- tests.sh | 20 ++++++++++++++++++++ tests/test_gid_minus_plus.out | 19 +++++++++++++++++++ tests/test_gid_plus_plus.out | 19 +++++++++++++++++++ tests/test_uid_minus_plus.out | 19 +++++++++++++++++++ tests/test_uid_plus_plus.out | 19 +++++++++++++++++++ 6 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 tests/test_gid_minus_plus.out create mode 100644 tests/test_gid_plus_plus.out create mode 100644 tests/test_uid_minus_plus.out create mode 100644 tests/test_uid_plus_plus.out diff --git a/parse.c b/parse.c index e2a3dbf..e6d58c5 100644 --- a/parse.c +++ b/parse.c @@ -658,10 +658,16 @@ static const char *parse_icmp(const struct parser_state *state, const char *str, * Check if a string could be an integer comparison. */ static bool looks_like_icmp(const char *str) { - if (str[0] == '-' || str[0] == '+') { - ++str; + int i; + + // One +/- for the comparison flag, one for the sign + for (i = 0; i < 2; ++i) { + if (str[i] != '-' && str[i] != '+') { + break; + } } - return str[0] >= '0' && str[0] <= '9'; + + return str[i] >= '0' && str[i] <= '9'; } /** diff --git a/tests.sh b/tests.sh index 9fef675..a986580 100755 --- a/tests.sh +++ b/tests.sh @@ -428,7 +428,9 @@ gnu_tests=( test_gid test_gid_plus + test_gid_plus_plus test_gid_minus + test_gid_minus_plus test_ignore_readdir_race test_ignore_readdir_race_root @@ -525,7 +527,9 @@ gnu_tests=( test_uid test_uid_plus + test_uid_plus_plus test_uid_minus + test_uid_minus_plus test_writable @@ -1018,10 +1022,18 @@ function test_gid_plus() { bfs_diff basic -gid +0 } +function test_gid_plus_plus() { + bfs_diff basic -gid +0 +} + function test_gid_minus() { bfs_diff basic -gid "-$(($(id -g) + 1))" } +function test_gid_minus_plus() { + bfs_diff basic -gid "-+$(($(id -g) + 1))" +} + function test_uid() { bfs_diff basic -uid "$(id -u)" } @@ -1030,10 +1042,18 @@ function test_uid_plus() { bfs_diff basic -uid +0 } +function test_uid_plus_plus() { + bfs_diff basic -uid ++0 +} + function test_uid_minus() { bfs_diff basic -uid "-$(($(id -u) + 1))" } +function test_uid_minus_plus() { + bfs_diff basic -uid "-+$(($(id -u) + 1))" +} + function test_newer() { bfs_diff times -newer times/a } diff --git a/tests/test_gid_minus_plus.out b/tests/test_gid_minus_plus.out new file mode 100644 index 0000000..bb3cd8d --- /dev/null +++ b/tests/test_gid_minus_plus.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_gid_plus_plus.out b/tests/test_gid_plus_plus.out new file mode 100644 index 0000000..bb3cd8d --- /dev/null +++ b/tests/test_gid_plus_plus.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_uid_minus_plus.out b/tests/test_uid_minus_plus.out new file mode 100644 index 0000000..bb3cd8d --- /dev/null +++ b/tests/test_uid_minus_plus.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_uid_plus_plus.out b/tests/test_uid_plus_plus.out new file mode 100644 index 0000000..bb3cd8d --- /dev/null +++ b/tests/test_uid_plus_plus.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 -- cgit v1.2.3