diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 9b5f292eec..9abc073da8 100644
a
|
b
|
function path_is_absolute( $path ) { |
1729 | 1729 | return true; |
1730 | 1730 | } |
1731 | 1731 | |
| 1732 | // Windows normalized paths for local filesystem and network shares (forward slahes) |
| 1733 | if ( preg_match( '#(^[a-zA-Z]+:/|^//[\w!@\#\$%\^\(\)\-\'{}\.~]{1,15})#', $path ) ) { |
| 1734 | return true; |
| 1735 | } |
| 1736 | |
1732 | 1737 | // A path starting with / or \ is absolute; anything else is relative. |
1733 | 1738 | return ( $path[0] == '/' || $path[0] == '\\' ); |
1734 | 1739 | } |
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index 1796ddeded..cc3167fdd6 100644
a
|
b
|
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 a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php
index c0b20bb2a7..5560074bf6 100644
a
|
b
|
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 | * @ticket 36308 |
| 1359 | */ |
| 1360 | function test_wp_get_attached_file() { |
| 1361 | |
| 1362 | $post = self::factory()->post->create_and_get( |
| 1363 | array( |
| 1364 | 'post_title' => 'example-page', |
| 1365 | 'post_type' => 'post' |
| 1366 | ) |
| 1367 | ); |
| 1368 | |
| 1369 | // Windows local file system path |
| 1370 | |
| 1371 | $attachment = self::factory()->attachment->create_and_get( |
| 1372 | array( |
| 1373 | 'post_parent' => $post->ID, |
| 1374 | 'file' => 'C:/WWW/Sites/demo/htdocs/wordpress/wp-content/uploads/2016/03/example.jpg', |
| 1375 | ) |
| 1376 | ); |
| 1377 | |
| 1378 | $attachment_path = get_attached_file( $attachment->ID ); |
| 1379 | |
| 1380 | $this->assertEquals( $attachment_path, 'C:/WWW/Sites/demo/htdocs/wordpress/wp-content/uploads/2016/03/example.jpg' ); |
| 1381 | |
| 1382 | // Windows network shares path |
| 1383 | |
| 1384 | $attachment = self::factory()->attachment->create_and_get( |
| 1385 | array( |
| 1386 | 'post_parent' => $post->ID, |
| 1387 | 'file' => '//ComputerName/ShareName/SubfolderName/example.txt', |
| 1388 | ) |
| 1389 | ); |
| 1390 | |
| 1391 | $attachment_path = get_attached_file( $attachment->ID ); |
| 1392 | |
| 1393 | $this->assertEquals( $attachment_path, '//ComputerName/ShareName/SubfolderName/example.txt' ); |
| 1394 | } |
| 1395 | |
1357 | 1396 | } |