|
9 | 9 | use WP_CLI\Fetchers; |
10 | 10 | use WP_CLI\Loggers; |
11 | 11 | use WP_CLI\Utils; |
| 12 | +use WP_CLI\Path; |
12 | 13 | use WP_Error; |
13 | 14 |
|
14 | 15 | /** |
@@ -284,7 +285,7 @@ public function install( $args, $assoc_args ) { |
284 | 285 | */ |
285 | 286 | global $wp_filesystem; |
286 | 287 |
|
287 | | - $source_dir = Utils\basename( $source ); // `$source` is trailing-slashed path to the unzipped archive directory. |
| 288 | + $source_dir = Path::basename( $source ); // `$source` is trailing-slashed path to the unzipped archive directory. |
288 | 289 | if ( $source_dir === $custom_slug ) { |
289 | 290 | return $source; |
290 | 291 | } |
@@ -314,15 +315,15 @@ public function install( $args, $assoc_args ) { |
314 | 315 | * @var string $path |
315 | 316 | */ |
316 | 317 | $path = Utils\parse_url( $slug, PHP_URL_PATH ); |
317 | | - $slug_dir = Utils\basename( $path, '.zip' ); |
| 318 | + $slug_dir = Path::basename( $path, '.zip' ); |
318 | 319 |
|
319 | 320 | // Don't use the zip name if archive attached to release, as name likely to contain version tag/branch. |
320 | 321 | if ( preg_match( '#github\.com/[^/]+/([^/]+)/archive/#', $slug, $matches ) ) { |
321 | 322 | // Note this will be wrong if the project name isn't the same as the plugin/theme slug name. |
322 | 323 | $slug_dir = $matches[1]; |
323 | 324 | } |
324 | 325 |
|
325 | | - $source_dir = Utils\basename( $source ); // `$source` is trailing-slashed path to the unzipped archive directory, so basename returns the unslashed directory. |
| 326 | + $source_dir = Path::basename( $source ); // `$source` is trailing-slashed path to the unzipped archive directory, so basename returns the unslashed directory. |
326 | 327 | if ( $source_dir === $slug_dir ) { |
327 | 328 | return $source; |
328 | 329 | } |
@@ -430,10 +431,10 @@ protected function install_from_php_file( $url, $assoc_args ) { |
430 | 431 |
|
431 | 432 | // Extract and validate filename before downloading. |
432 | 433 | $url_path = (string) Utils\parse_url( $url, PHP_URL_PATH ); |
433 | | - $filename = Utils\basename( $url_path ); |
| 434 | + $filename = Path::basename( $url_path ); |
434 | 435 |
|
435 | 436 | // Validate the filename doesn't contain directory separators or relative path components. |
436 | | - // Note: Utils\basename() already strips directory components (including ".."), so this check |
| 437 | + // Note: Path::basename() already strips directory components (including ".."), so this check |
437 | 438 | // is primarily a defense-in-depth safeguard in case its behavior changes or is bypassed. |
438 | 439 | if ( strpos( $filename, '/' ) !== false || strpos( $filename, '\\' ) !== false || strpos( $filename, '..' ) !== false ) { |
439 | 440 | return new WP_Error( 'invalid_filename', 'The filename contains invalid path components.' ); |
|
0 commit comments