diff --git src/wp-includes/functions.php src/wp-includes/functions.php
index 53a2204..6d89810 100644
|
|
function wp_mkdir_p( $target ) { |
1715 | 1715 | * For example, '/foo/bar', or 'c:\windows'. |
1716 | 1716 | * |
1717 | 1717 | * @since 2.5.0 |
| 1718 | * @since 5.0.0 Allows Windows normalized paths (forward slashes). |
1718 | 1719 | * |
1719 | 1720 | * @param string $path File path. |
1720 | 1721 | * @return bool True if path is absolute, false is not absolute. |
… |
… |
function path_is_absolute( $path ) { |
1737 | 1738 | return true; |
1738 | 1739 | } |
1739 | 1740 | |
| 1741 | // Windows normalized paths for local filesystem and network shares (forward slashes). |
| 1742 | if ( preg_match( '#(^[a-zA-Z]+:/|^//[\w!@\#\$%\^\(\)\-\'{}\.~]{1,15})#', $path ) ) { |
| 1743 | return true; |
| 1744 | } |
| 1745 | |
1740 | 1746 | // A path starting with / or \ is absolute; anything else is relative. |
1741 | 1747 | return ( $path[0] == '/' || $path[0] == '\\' ); |
1742 | 1748 | } |
diff --git src/wp-includes/post.php src/wp-includes/post.php
index 52fb119..3b94f5e 100644
|
|
function create_initial_post_types() { |
320 | 320 | function get_attached_file( $attachment_id, $unfiltered = false ) { |
321 | 321 | $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); |
322 | 322 | |
323 | | // If the file is relative, prepend upload dir. |
324 | | if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) { |
325 | | $file = $uploads['basedir'] . "/$file"; |
| 323 | if ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) { |
| 324 | $file = path_join( $uploads['basedir'], $file ); |
326 | 325 | } |
327 | 326 | |
328 | 327 | if ( $unfiltered ) { |
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
index d9e3d5f..09f9636 100644
|
|
class Tests_Functions extends WP_UnitTestCase { |
101 | 101 | 'C:\\', |
102 | 102 | 'C:\\WINDOWS', |
103 | 103 | '\\\\sambashare\\foo', |
| 104 | 'c:/', |
| 105 | 'c://', |
| 106 | '//', |
| 107 | 'c:/FOO', |
| 108 | '//FOO', |
| 109 | 'C:/WWW/Sites/demo/htdocs/wordpress/wp-content/uploads/2016/03/example.jpg', |
| 110 | '//ComputerName/ShareName/SubfolderName/example.txt', |
104 | 111 | ); |
105 | 112 | foreach ( $absolute_paths as $path ) { |
106 | 113 | $this->assertTrue( path_is_absolute( $path ), "path_is_absolute('$path') should return true" ); |
… |
… |
class Tests_Functions extends WP_UnitTestCase { |
115 | 122 | '../foo', |
116 | 123 | '../', |
117 | 124 | '../foo.bar', |
| 125 | 'foo.bar', |
118 | 126 | 'foo/bar', |
119 | 127 | 'foo', |
120 | 128 | 'FOO', |
121 | 129 | '..\\WINDOWS', |
| 130 | '..//WINDOWS', |
| 131 | 'c:', |
| 132 | 'C:', |
122 | 133 | ); |
123 | 134 | foreach ( $relative_paths as $path ) { |
124 | 135 | $this->assertFalse( path_is_absolute( $path ), "path_is_absolute('$path') should return false" ); |
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
index c0b20bb..b38e9b8 100644
|
|
class Tests_Post extends WP_UnitTestCase { |
1354 | 1354 | $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) ); |
1355 | 1355 | } |
1356 | 1356 | |
| 1357 | /** |
| 1358 | * Testing the wp_get_attached_file() function. |
| 1359 | * |
| 1360 | * @ticket 36308 |
| 1361 | */ |
| 1362 | public function test_wp_get_attached_file() { |
| 1363 | |
| 1364 | $post = self::factory()->post->create_and_get( |
| 1365 | array( |
| 1366 | 'post_title' => 'example-page', |
| 1367 | 'post_type' => 'post', |
| 1368 | ) |
| 1369 | ); |
| 1370 | |
| 1371 | // Windows local file system path. |
| 1372 | $attachment = self::factory()->attachment->create_and_get( |
| 1373 | array( |
| 1374 | 'post_parent' => $post->ID, |
| 1375 | 'file' => 'C:/WWW/Sites/demo/htdocs/wordpress/wp-content/uploads/2016/03/example.jpg', |
| 1376 | ) |
| 1377 | ); |
| 1378 | $attachment_path = get_attached_file( $attachment->ID ); |
| 1379 | $this->assertEquals( $attachment_path, 'C:/WWW/Sites/demo/htdocs/wordpress/wp-content/uploads/2016/03/example.jpg' ); |
| 1380 | |
| 1381 | // Windows network shares path. |
| 1382 | $attachment = self::factory()->attachment->create_and_get( |
| 1383 | array( |
| 1384 | 'post_parent' => $post->ID, |
| 1385 | 'file' => '//ComputerName/ShareName/SubfolderName/example.txt', |
| 1386 | ) |
| 1387 | ); |
| 1388 | $attachment_path = get_attached_file( $attachment->ID ); |
| 1389 | $this->assertEquals( $attachment_path, '//ComputerName/ShareName/SubfolderName/example.txt' ); |
| 1390 | } |
| 1391 | |
1357 | 1392 | } |