diff --git a/features/find.feature b/features/find.feature index 7b2cb92..ae50d10 100644 --- a/features/find.feature +++ b/features/find.feature @@ -217,3 +217,44 @@ Feature: Find WordPress installs on the filesystem """ 1 """ + + Scenario: Directories with ignored path as substring should not be ignored + Given a WP install in 'wpblogs' + And a WP install in 'myjs' + And a WP install in 'logs' + And a WP install in 'js' + + When I run `wp eval --skip-wordpress 'echo realpath( getenv( "RUN_DIR" ) );'` + Then save STDOUT as {TEST_DIR} + + When I run `wp find {TEST_DIR} --field=version_path --verbose` + Then STDOUT should contain: + """ + Found WordPress installation at '{TEST_DIR}/wpblogs/wp-includes/version.php' + """ + And STDOUT should contain: + """ + Found WordPress installation at '{TEST_DIR}/myjs/wp-includes/version.php' + """ + And STDOUT should not contain: + """ + Found WordPress installation at '{TEST_DIR}/logs/wp-includes/version.php' + """ + And STDOUT should not contain: + """ + Found WordPress installation at '{TEST_DIR}/js/wp-includes/version.php' + """ + And STDOUT should contain: + """ + Matched ignored path. Skipping recursion into '{TEST_DIR}/logs/' + """ + And STDOUT should contain: + """ + Matched ignored path. Skipping recursion into '{TEST_DIR}/js/' + """ + + When I run `wp find {TEST_DIR} --format=count` + Then STDOUT should be: + """ + 2 + """ diff --git a/src/Find_Command.php b/src/Find_Command.php index f2a0fe5..02ef100 100644 --- a/src/Find_Command.php +++ b/src/Find_Command.php @@ -244,7 +244,8 @@ private function recurse_directory( $path ) { return; } foreach ( $this->ignored_paths as $ignored_path ) { - if ( false !== stripos( $compared_path, $ignored_path ) ) { + // Match at directory boundaries using regex to ensure we match complete directory names + if ( preg_match( '#(^|/)' . preg_quote( $ignored_path, '#' ) . '#i', $compared_path ) ) { $this->log( "Matched ignored path. Skipping recursion into '{$path}'" ); return; }