Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions features/find.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
3 changes: 2 additions & 1 deletion src/Find_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading