Skip to content

Commit dd22d61

Browse files
Copilotswissspidy
andcommitted
Fix ignored_paths false positives by matching at directory boundaries
Co-authored-by: swissspidy <[email protected]>
1 parent 9022175 commit dd22d61

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

features/find.feature

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,44 @@ Feature: Find WordPress installs on the filesystem
217217
"""
218218
1
219219
"""
220+
221+
Scenario: Directories with ignored path as substring should not be ignored
222+
Given a WP install in 'wpblogs'
223+
And a WP install in 'myjs'
224+
And a WP install in 'logs'
225+
And a WP install in 'js'
226+
227+
When I run `wp eval --skip-wordpress 'echo realpath( getenv( "RUN_DIR" ) );'`
228+
Then save STDOUT as {TEST_DIR}
229+
230+
When I run `wp find {TEST_DIR} --field=version_path --verbose`
231+
Then STDOUT should contain:
232+
"""
233+
Found WordPress installation at '{TEST_DIR}/wpblogs/wp-includes/version.php'
234+
"""
235+
And STDOUT should contain:
236+
"""
237+
Found WordPress installation at '{TEST_DIR}/myjs/wp-includes/version.php'
238+
"""
239+
And STDOUT should not contain:
240+
"""
241+
Found WordPress installation at '{TEST_DIR}/logs/wp-includes/version.php'
242+
"""
243+
And STDOUT should not contain:
244+
"""
245+
Found WordPress installation at '{TEST_DIR}/js/wp-includes/version.php'
246+
"""
247+
And STDOUT should contain:
248+
"""
249+
Matched ignored path. Skipping recursion into '{TEST_DIR}/logs/'
250+
"""
251+
And STDOUT should contain:
252+
"""
253+
Matched ignored path. Skipping recursion into '{TEST_DIR}/js/'
254+
"""
255+
256+
When I run `wp find {TEST_DIR} --format=count`
257+
Then STDOUT should be:
258+
"""
259+
2
260+
"""

src/Find_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ private function recurse_directory( $path ) {
244244
return;
245245
}
246246
foreach ( $this->ignored_paths as $ignored_path ) {
247-
if ( false !== stripos( $compared_path, $ignored_path ) ) {
247+
// Match at directory boundaries: either at the start or after a directory separator
248+
if ( 0 === stripos( $compared_path, $ignored_path ) || false !== stripos( $compared_path, '/' . $ignored_path ) ) {
248249
$this->log( "Matched ignored path. Skipping recursion into '{$path}'" );
249250
return;
250251
}

0 commit comments

Comments
 (0)