WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/20/2017 02:23:00 AM (2 years ago)
Author:
mikeschroder
Message:

Media: Decode HTML entities in author_name before sending to JS.

In wp_prepare_attachment_for_js():

  • Normalize behavior when author does not exist by returning '(no author)' for authorName in these cases.
  • Decode HTML entities in author_name.
  • Add tests for both of the above.

Props arshidkv12, ocean90, sloisel, mikeschroder.
Fixes #39955.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r40070 r40809  
    268268        $this->assertEquals( 'image', $prepped['type'] );
    269269        $this->assertEquals( '', $prepped['subtype'] );
     270
     271        // Test that if author is not found, we return "(no author)" as `display_name`.
     272        // The previously used test post contains no author, so we can reuse it.
     273        $this->assertEquals( '(no author)', $prepped['authorName'] );
     274
     275        // Test that if author has HTML entities in display_name, they're decoded correctly.
     276        $html_entity_author = self::factory()->user->create( array(
     277            'display_name' => 'You & Me',
     278        ) );
     279        $post->post_author = $html_entity_author;
     280        $prepped = wp_prepare_attachment_for_js( $post );
     281        $this->assertEquals( 'You & Me', $prepped['authorName'] );
    270282    }
    271283
Note: See TracChangeset for help on using the changeset viewer.