Make WordPress Core

Changeset 36853


Ignore:
Timestamp:
03/05/2016 03:55:33 AM (9 years ago)
Author:
johnbillion
Message:

Posts, Post Types: Ensure that non-ASCII characters in attachment slugs aren't shown in urlencoded form in the sample permalink UI.

Fixes #35980

Location:
trunk
Files:
2 edited

Legend:

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

    r36659 r36853  
    13031303            } else {
    13041304                // Allow non-published (private, future) to be viewed at a pretty permalink.
    1305                 $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, urldecode( $permalink ) );
     1305                $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
    13061306            }
    13071307        }
     
    13131313
    13141314        if ( false !== $view_link ) {
    1315             $return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $view_link . "</a>\n";
     1315            $display_link = urldecode( $view_link );
     1316            $return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $display_link . "</a>\n";
    13161317        } else {
    13171318            $return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r36253 r36853  
    281281        $found = get_sample_permalink_html( $p );
    282282        $this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found );
     283        $this->assertContains( '>' . get_option( 'home' ) . '/?p=' . $p . '<', $found );
    283284    }
    284285
     
    293294
    294295        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
    295         $p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );
     296        $p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'foo-صورة', 'post_date' => $future_date ) );
    296297
    297298        $found = get_sample_permalink_html( $p );
    298299        $post = get_post( $p );
    299300        $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found );
     301        $this->assertContains( '>' . urldecode( $post->post_name ) . '<', $found );
     302    }
     303
     304    /**
     305     * @ticket 35980
     306     */
     307    public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_attachment_link_when_pretty_permalinks_are_enabled() {
     308        $this->set_permalink_structure( '/%postname%/' );
     309
     310        wp_set_current_user( self::$admin_id );
     311
     312        $p = self::factory()->attachment->create_object( 'صورة.jpg', 0, array(
     313            'post_mime_type' => 'image/jpeg',
     314            'post_type'      => 'attachment',
     315            'post_title'     => 'صورة',
     316            'post_status'    => 'inherit',
     317        ) );
     318
     319        $found = get_sample_permalink_html( $p );
     320        $post = get_post( $p );
     321        $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found );
     322        $this->assertContains( '>' . urldecode( get_permalink( $post ) ) . '<', $found );
    300323    }
    301324
     
    310333
    311334        // Published posts should use published permalink
    312         $p = self::factory()->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo' ) );
    313 
    314         $found = get_sample_permalink_html( $p, null, 'new_slug' );
     335        $p = self::factory()->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo-صورة' ) );
     336
     337        $found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
    315338        $post = get_post( $p );
    316339        $message = 'Published post';
    317340        $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found, $message );
     341        $this->assertContains( '>new_slug-صورة<', $found, $message );
    318342
    319343        // Scheduled posts should use published permalink
    320344        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
    321         $p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'bar', 'post_date' => $future_date ) );
    322 
    323         $found = get_sample_permalink_html( $p, null, 'new_slug' );
     345        $p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'bar-صورة', 'post_date' => $future_date ) );
     346
     347        $found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
    324348        $post = get_post( $p );
    325349        $message = 'Scheduled post';
    326350        $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found, $message );
     351        $this->assertContains( '>new_slug-صورة<', $found, $message );
    327352
    328353        // Draft posts should use preview link
    329         $p = self::factory()->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz' ) );
    330 
    331         $found = get_sample_permalink_html( $p, null, 'new_slug' );
     354        $p = self::factory()->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz-صورة' ) );
     355
     356        $found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
    332357        $post = get_post( $p );
    333358        $message = 'Draft post';
     
    337362
    338363        $this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message );
     364        $this->assertContains( '>new_slug-صورة<', $found, $message );
    339365    }
    340366
Note: See TracChangeset for help on using the changeset viewer.