Skip to content

Commit 5eeb1af

Browse files
authored
Apply suggestions from code review
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
1 parent 059e826 commit 5eeb1af

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Core_Command.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,10 +1974,9 @@ private function remove_old_files_from_list( $files ) {
19741974
// Symlinks: validate and remove without following the link.
19751975
if ( is_link( $file_path ) ) {
19761976
$normalized_path = realpath( dirname( $file_path ) );
1977-
if ( false === $normalized_path
1978-
|| ( 0 !== strpos( Utils\trailingslashit( $normalized_path ), $abspath_realpath_trailing )
1979-
&& rtrim( $abspath_realpath_trailing, '/' ) !== $normalized_path )
1980-
) {
1977+
if ( false === $normalized_path
1978+
|| 0 !== strpos( Utils\trailingslashit( $normalized_path ), $abspath_realpath_trailing )
1979+
) {
19811980
WP_CLI::debug( "Skipping symbolic link outside of ABSPATH: {$file}", 'core' );
19821981
continue;
19831982
}
@@ -1992,7 +1991,7 @@ private function remove_old_files_from_list( $files ) {
19921991

19931992
// Regular files/directories: validate real path is within ABSPATH.
19941993
$file_realpath = realpath( $file_path );
1995-
if ( false === $file_realpath || 0 !== strpos( $file_realpath, $abspath_realpath_trailing ) ) {
1994+
if ( false === $file_realpath || 0 !== strpos( Utils\trailingslashit( $file_realpath ), $abspath_realpath_trailing ) ) {
19961995
WP_CLI::debug( "Skipping file outside of ABSPATH: {$file}", 'core' );
19971996
continue;
19981997
}
@@ -2028,7 +2027,7 @@ private function remove_directory( $dir, $abspath_realpath_trailing ) {
20282027
WP_CLI::debug( "Failed to resolve realpath for directory: {$dir}", 'core' );
20292028
return false;
20302029
}
2031-
if ( 0 !== strpos( $dir_realpath, $abspath_realpath_trailing ) ) {
2030+
if ( 0 !== strpos( Utils\trailingslashit( $dir_realpath ), $abspath_realpath_trailing ) ) {
20322031
WP_CLI::debug( "Attempted to remove directory outside of ABSPATH: {$dir_realpath}", 'core' );
20332032
return false;
20342033
}

0 commit comments

Comments
 (0)