Make WordPress Core

Changeset 33705


Ignore:
Timestamp:
08/22/2015 04:38:09 PM (9 years ago)
Author:
wonderboymusic
Message:

Ensure that attachment_url_to_postid() matches cross-scheme when front-end and back-end schemes are different.

Adds unit test.

Props welcher.
Fixes #33109.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r33643 r33705  
    34323432    $path = $url;
    34333433
     3434    $site_url = parse_url( $dir['url'] );
     3435    $image_path = parse_url( $path );
     3436
     3437    //force the protocols to match if needed
     3438    if ( isset( $image_path['scheme'] ) && ( $image_path['scheme'] !== $site_url['scheme'] ) ) {
     3439        $path = str_replace( $image_path['scheme'], $site_url['scheme'], $path );
     3440    }
     3441
    34343442    if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) {
    34353443        $path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
     
    34503458     * @param string   $url     The URL being looked up.
    34513459     */
    3452     $post_id = apply_filters( 'attachment_url_to_postid', $post_id, $url );
    3453 
    3454     return (int) $post_id;
     3460    return (int) apply_filters( 'attachment_url_to_postid', $post_id, $url );
    34553461}
    34563462
  • trunk/tests/phpunit/tests/media.php

    r33506 r33705  
    534534        $image_url  = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;
    535535        $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
     536    }
     537
     538    function test_attachment_url_to_postid_schemes() {
     539        $image_path = '2014/11/' . $this->img_name;
     540        $attachment_id = $this->factory->attachment->create_object( $image_path, 0, array(
     541            'post_mime_type' => 'image/jpeg',
     542            'post_type'      => 'attachment',
     543        ) );
     544
     545        /**
     546         * @ticket 33109 Testing protocols not matching
     547         */
     548        $image_url  = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;
     549        $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
     550    }
     551
     552    function test_attachment_url_to_postid_filtered() {
     553        $image_path = '2014/11/' . $this->img_name;
     554        $attachment_id = $this->factory->attachment->create_object( $image_path, 0, array(
     555            'post_mime_type' => 'image/jpeg',
     556            'post_type'      => 'attachment',
     557        ) );
    536558
    537559        add_filter( 'upload_dir', array( $this, '_upload_dir' ) );
Note: See TracChangeset for help on using the changeset viewer.