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

Fixes #35980


git-svn-id: https://develop.svn.wordpress.org/trunk@36853 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2016-03-05 03:55:33 +00:00
parent ae1c49027a
commit 48959ec76e
2 changed files with 36 additions and 9 deletions

View File

@ -1302,7 +1302,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
$view_link = get_permalink( $post );
} else {
// Allow non-published (private, future) to be viewed at a pretty permalink.
$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, urldecode( $permalink ) );
$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
}
}
}
@ -1312,7 +1312,8 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
if ( false !== $view_link ) {
$return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $view_link . "</a>\n";
$display_link = urldecode( $view_link );
$return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $display_link . "</a>\n";
} else {
$return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
}

View File

@ -280,6 +280,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$found = get_sample_permalink_html( $p );
$this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found );
$this->assertContains( '>' . get_option( 'home' ) . '/?p=' . $p . '<', $found );
}
/**
@ -292,11 +293,33 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
wp_set_current_user( self::$admin_id );
$future_date = date( 'Y-m-d H:i:s', time() + 100 );
$p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );
$p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'foo-صورة', 'post_date' => $future_date ) );
$found = get_sample_permalink_html( $p );
$post = get_post( $p );
$this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found );
$this->assertContains( '>' . urldecode( $post->post_name ) . '<', $found );
}
/**
* @ticket 35980
*/
public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_attachment_link_when_pretty_permalinks_are_enabled() {
$this->set_permalink_structure( '/%postname%/' );
wp_set_current_user( self::$admin_id );
$p = self::factory()->attachment->create_object( 'صورة.jpg', 0, array(
'post_mime_type' => 'image/jpeg',
'post_type' => 'attachment',
'post_title' => 'صورة',
'post_status' => 'inherit',
) );
$found = get_sample_permalink_html( $p );
$post = get_post( $p );
$this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found );
$this->assertContains( '>' . urldecode( get_permalink( $post ) ) . '<', $found );
}
/**
@ -309,26 +332,28 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
wp_set_current_user( self::$admin_id );
// Published posts should use published permalink
$p = self::factory()->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo' ) );
$p = self::factory()->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo-صورة' ) );
$found = get_sample_permalink_html( $p, null, 'new_slug' );
$found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
$post = get_post( $p );
$message = 'Published post';
$this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found, $message );
$this->assertContains( '>new_slug-صورة<', $found, $message );
// Scheduled posts should use published permalink
$future_date = date( 'Y-m-d H:i:s', time() + 100 );
$p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'bar', 'post_date' => $future_date ) );
$p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'bar-صورة', 'post_date' => $future_date ) );
$found = get_sample_permalink_html( $p, null, 'new_slug' );
$found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
$post = get_post( $p );
$message = 'Scheduled post';
$this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found, $message );
$this->assertContains( '>new_slug-صورة<', $found, $message );
// Draft posts should use preview link
$p = self::factory()->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz' ) );
$p = self::factory()->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz-صورة' ) );
$found = get_sample_permalink_html( $p, null, 'new_slug' );
$found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
$post = get_post( $p );
$message = 'Draft post';
@ -336,6 +361,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$preview_link = add_query_arg( 'preview', 'true', $preview_link );
$this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message );
$this->assertContains( '>new_slug-صورة<', $found, $message );
}
/**