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
5 changes: 5 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,11 @@ function wp_mkdir_p( $target ) {
* @phpstan-assert-if-true non-falsy-string $path
*/
function path_is_absolute( $path ) {
// Only a string can be a path. Anything else, such as a post ID, is not absolute.
if ( ! is_string( $path ) ) {
return false;
}

/*
* Check to see if the path is a stream and check to see if its an actual
* path or file as realpath() does not support stream wrappers.
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,40 @@ public function test_path_is_not_absolute() {
}
}

/**
* @ticket 59729
*
* @dataProvider data_path_is_absolute_non_string
*
* @param mixed $path Value that is not a string.
*/
public function test_path_is_absolute_returns_false_for_non_string( $path ) {
$this->assertFalse( path_is_absolute( $path ) );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_path_is_absolute_non_string() {
return array(
'integer' => array( 1 ),
'zero' => array( 0 ),
'float' => array( 1.5 ),
'true' => array( true ),
'null' => array( null ),
'array' => array( array( '/foo' ) ),
);
}

/**
* @ticket 59729
*/
public function test_path_join_with_integer_path() {
$this->assertSame( '/foo/123', path_join( '/foo', 123 ) );
}

/**
* Tests path_join().
*
Expand Down
Loading