Make WordPress Core

Ticket #36308: 36308.3.diff

File 36308.3.diff, 2.7 KB (added by stevenlinx, 7 years ago)
  • src/wp-includes/functions.php

    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 ) { 
    17291729                return true;
    17301730        }
    17311731
     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
    17321737        // A path starting with / or \ is absolute; anything else is relative.
    17331738        return ( $path[0] == '/' || $path[0] == '\\' );
    17341739}
  • src/wp-includes/post.php

    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() { 
    320320function get_attached_file( $attachment_id, $unfiltered = false ) {
    321321        $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
    322322
    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);
    326325        }
    327326
    328327        if ( $unfiltered ) {
  • tests/phpunit/tests/post.php

    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 { 
    13541354                $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
    13551355        }
    13561356
     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
    13571396}