Ticket #52995: 52995.diff
File 52995.diff, 1.8 KB (added by , 3 years ago) |
---|
-
src/wp-includes/post.php
2558 2558 } else { 2559 2559 $value = format_to_edit( $value ); 2560 2560 } 2561 } else {2561 } elseif ( ! in_array( $field, $int_fields, true ) || ! is_int( $value ) ) { 2562 2562 $value = esc_attr( $value ); 2563 2563 } 2564 2564 } elseif ( 'db' === $context ) { … … 2626 2626 $value = apply_filters( "post_{$field}", $value, $post_id, $context ); 2627 2627 } 2628 2628 2629 if ( 'attribute' === $context ) { 2630 $value = esc_attr( $value ); 2631 } elseif ( 'js' === $context ) { 2632 $value = esc_js( $value ); 2629 if ( ! in_array( $field, $int_fields, true ) || ! is_int( $value ) ) { 2630 if ( 'attribute' === $context ) { 2631 $value = esc_attr( $value ); 2632 } elseif ( 'js' === $context ) { 2633 $value = esc_js( $value ); 2634 } 2633 2635 } 2634 2636 } 2635 2637 -
tests/phpunit/tests/post/objects.php
184 184 $this->assertSame( esc_js( "Mary's home" ), $raw_post->post_title ); 185 185 } 186 186 187 /** 188 * @ticket 52995 189 */ 190 function test_numeric_properties_should_be_cast_to_ints() { 191 $post_id = self::factory()->post->create(); 192 $contexts = array( 'raw', 'edit', 'db', 'display', 'attribute', 'js' ); 193 194 foreach ( $contexts as $context ) { 195 $post = get_post( $post_id, OBJECT, $context ); 196 197 $this->assertSame( $context, $post->filter ); 198 $this->assertInternalType( 'int', $post->ID ); 199 $this->assertInternalType( 'int', $post->post_parent ); 200 $this->assertInternalType( 'int', $post->menu_order ); 201 } 202 } 203 187 204 function test_get_post_identity() { 188 205 $post = get_post( self::factory()->post->create() ); 189 206