Make WordPress Core

Ticket #20009: 20009.4.diff

File 20009.4.diff, 3.3 KB (added by whyisjake, 6 years ago)
  • src/wp-includes/post-template.php

     
    454454 */
    455455function post_class( $class = '', $post_id = null ) {
    456456        // Separates classes with a single space, collates classes for post DIV.
    457         echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
     457        echo 'class="' . esc_attr( join( ' ', get_post_class( $class, $post_id ) ) ) . '"';
    458458}
    459459
    460460/**
    … …  
    590590 */
    591591function body_class( $class = '' ) {
    592592        // Separates class names with a single space, collates class names for body element.
    593         echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
     593        echo 'class="' . esc_attr( join( ' ', get_body_class( $class ) ) ) . '"';
    594594}
    595595
    596596/**
  • tests/phpunit/tests/post/bodyClass.php

     
     1<?php
     2
     3/**
     4 * @group post
     5 * @covers ::body_class
     6 */
     7class Tests_Post_BodyClass extends WP_UnitTestCase {
     8        protected $post_id;
     9
     10        public function setUp() {
     11                parent::setUp();
     12                $this->post_id = self::factory()->post->create();
     13        }
     14
     15        public function test_body_class() {
     16                $expected = 'class="' . join( ' ', get_body_class( '', $this->post_id ) ) . '"';
     17                $this->expectOutputString( $expected );
     18                body_class( '', $this->post_id );
     19        }
     20
     21        public function test_body_class_extra_esc_attr() {
     22                $classes              = get_body_class( '', $this->post_id );
     23                $escaped_again        = array_map( 'esc_attr', $classes );
     24                $escaped_another_time = 'class="' . esc_attr( join( ' ', $escaped_again ) ) . '"';
     25
     26                $this->expectOutputString( $escaped_another_time );
     27                body_class( '', $this->post_id );
     28        }
     29}
  • tests/phpunit/tests/post/postClass.php

    Property changes on: tests/phpunit/tests/post/bodyClass.php
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1<?php
     2
     3/**
     4 * @group post
     5 * @covers ::post_class
     6 */
     7class Tests_Post_PostClass extends WP_UnitTestCase {
     8        protected $post_id;
     9
     10        public function setUp() {
     11                parent::setUp();
     12                $this->post_id = self::factory()->post->create();
     13        }
     14
     15        public function test_post_class() {
     16                $expected = 'class="' . join( ' ', get_post_class( '', $this->post_id ) ) . '"';
     17                $this->expectOutputString( $expected );
     18                post_class( '', $this->post_id );
     19        }
     20
     21        public function test_post_class_extra_esc_attr() {
     22                $classes              = get_post_class( '', $this->post_id );
     23                $escaped_again        = array_map( 'esc_attr', $classes );
     24                $escaped_another_time = 'class="' . esc_attr( join( ' ', $escaped_again ) ) . '"';
     25
     26                $this->expectOutputString( $escaped_another_time );
     27                post_class( '', $this->post_id );
     28        }
     29}