This fixes the case where someone's done something (weird) like:

  find src/*.c -name foo.c

Previously the match would fail because one side of the comparison was
already a path.
---
 tests/find.test   | 3 +++
 toys/posix/find.c | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)
From 41f0fd9ad4e67772478793eb2cf48a2372620ebe Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 29 Aug 2019 13:44:59 -0700
Subject: [PATCH] find: fix -name corner case.

This fixes the case where someone's done something (weird) like:

  find src/*.c -name foo.c

Previously the match would fail because one side of the comparison was
already a path.
---
 tests/find.test   | 3 +++
 toys/posix/find.c | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/find.test b/tests/find.test
index b3e2c4fa..1f59149b 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -122,4 +122,7 @@ testing "missing root error" \
   "LANG=C find -L dir/missing-root 2>err ; grep -q dir/missing-root err || echo missing error" \
   "" "" ""
 
+testing "-path match root" "find dir/f* -path dir/file" "dir/file\n" "" ""
+testing "-name match root" "find dir/f* -name file" "dir/file\n" "" ""
+
 rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 58a6f88d..02fdf3c4 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -368,7 +368,8 @@ static int do_find(struct dirtree *new)
         }
 
         if (check) {
-          test = !fnmatch(arg, name, FNM_PATHNAME*(!is_path));
+          test = !fnmatch(arg, is_path ? name : basename(name),
+            FNM_PATHNAME*(!is_path));
           if (i) free(name);
         }
         free(path);
-- 
2.23.0.187.g17f5b7556c-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to