Ticket #29807: 29807.7.diff
| File 29807.7.diff, 6.7 KB (added by , 8 years ago) |
|---|
-
src/wp-includes/kses.php
diff --git src/wp-includes/kses.php src/wp-includes/kses.php index 20790d1c44..232265a888 100644
if ( ! CUSTOM_TAGS ) { 239 239 'longdesc' => true, 240 240 'vspace' => true, 241 241 'src' => true, 242 'srcset' => true, 242 243 'usemap' => true, 243 244 'width' => true, 244 245 ), … … if ( ! CUSTOM_TAGS ) { 276 277 'lang' => true, 277 278 'xml:lang' => true, 278 279 ), 280 'picture' => array(), 279 281 'pre' => array( 280 282 'width' => true, 281 283 ), … … if ( ! CUSTOM_TAGS ) { 297 299 'xml:lang' => true, 298 300 ), 299 301 'small' => array(), 302 'source' => array( 303 'srcset' => true, 304 'type' => true, 305 'media' => true, 306 'sizes' => true, 307 ), 300 308 'strike' => array(), 301 309 'strong' => array(), 302 310 'sub' => array(), … … function wp_kses_hair( $attr, $allowed_protocols ) { 1140 1148 $attrarr = array(); 1141 1149 $mode = 0; 1142 1150 $attrname = ''; 1143 $uris = array( 'xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');1151 $uris = array('xmlns', 'profile', 'href', 'src', 'srcset', 'sizes', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action'); 1144 1152 1145 1153 // Loop through the whole attribute list 1146 1154 … … function wp_kses_hair( $attr, $allowed_protocols ) { 1186 1194 // "value" 1187 1195 $thisval = $match[1]; 1188 1196 if ( in_array( strtolower( $attrname ), $uris ) ) { 1189 $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols ); 1197 $thesevals = preg_split( '/\s*,\s*/', $thisval ); 1198 foreach ( (array) $thesevals as $key => $val ) { 1199 $thesevals[$key] = wp_kses_bad_protocol( $val, $allowed_protocols ); 1200 } 1201 $thisval = join(', ',$thesevals); 1190 1202 } 1191 1203 1192 1204 if ( false === array_key_exists( $attrname, $attrarr ) ) { … … function wp_kses_hair( $attr, $allowed_protocols ) { 1207 1219 // 'value' 1208 1220 $thisval = $match[1]; 1209 1221 if ( in_array( strtolower( $attrname ), $uris ) ) { 1210 $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols ); 1222 $thesevals = preg_split( '/\s*,\s*/', $thisval ); 1223 foreach ( (array) $thesevals as $key => $val ) { 1224 $thesevals[$key] = wp_kses_bad_protocol( $val, $allowed_protocols ); 1225 } 1226 $thisval = join(', ',$thesevals); 1211 1227 } 1212 1228 1213 1229 if ( false === array_key_exists( $attrname, $attrarr ) ) { … … function wp_kses_hair( $attr, $allowed_protocols ) { 1228 1244 // value 1229 1245 $thisval = $match[1]; 1230 1246 if ( in_array( strtolower( $attrname ), $uris ) ) { 1231 $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols ); 1247 $thesevals = preg_split( '/\s*,\s*/', $thisval ); 1248 foreach ( (array) $thesevals as $key => $val ) { 1249 $thesevals[$key] = wp_kses_bad_protocol( $val, $allowed_protocols ); 1250 } 1251 $thisval = join(', ',$thesevals); 1232 1252 } 1233 1253 1234 1254 if ( false === array_key_exists( $attrname, $attrarr ) ) { -
tests/phpunit/tests/kses.php
diff --git tests/phpunit/tests/kses.php tests/phpunit/tests/kses.php index 5ae0101dab..02fe863860 100644
class Tests_Kses extends WP_UnitTestCase { 75 75 } 76 76 } 77 77 78 function test_feed_links() { 78 /** 79 * @ticket 29807 80 */ 81 function test_wp_filter_post_kses_img() { 79 82 global $allowedposttags; 80 83 84 $attributes = array( 85 'class' => 'classname', 86 'id' => 'idattr', 87 'style' => 'color: red;', 88 'alt' => 'alt', 89 'src' => '/test.png', 90 'srcset' => '/test.png 1x, /test-2x.png 2x', 91 'width' => '100', 92 'height' => '100', 93 'usemap' => '#hash', 94 'vspace' => '20', 95 'hspace' => '20', 96 'longdesc' => 'this is the longdesc', 97 'align' => 'middle', 98 'border' => '5', 99 ); 100 101 foreach ( $attributes as $name => $value ) { 102 if ( $name === $value ) { 103 $string = "<img $value />"; 104 $expect_string = '<img ' . trim( $value, ';' ) . ' />'; 105 } else { 106 $string = "<img $name='$value' />"; 107 $expect_string = "<img $name='" . trim( $value, ';' ) . "' />"; 108 } 109 110 $this->assertEquals( $expect_string, wp_kses( $string, $allowedposttags ) ); 111 } 112 } 113 114 /** 115 * @ticket 29807 116 * 117 * @param string $unfiltered Unfiltered srcset value before wp_kses. 118 * @param string $expected Expected srset value after wp_kses. 119 * 120 * @dataProvider data_wp_kses_srcset 121 */ 122 function test_wp_kses_srcset( $unfiltered, $expected ) { 123 $unfiltered = "<img src='test.png' srcset='{$unfiltered}' />"; 124 $expected = "<img src='test.png' srcset='{$expected}' />"; 125 $this->assertEquals( $expected, wp_kses_post( $unfiltered ) ); 126 } 127 128 function data_wp_kses_srcset() { 129 return array( 130 array( 131 '/test.png 1x, /test-2x.png 2x', 132 '/test.png 1x, /test-2x.png 2x', 133 ), 134 array( 135 'bad://localhost/test.png 1x, http://localhost/test-2x.png 2x', 136 '//localhost/test.png 1x, http://localhost/test-2x.png 2x', 137 ), 138 array( 139 'http://localhost/test.png 1x, bad://localhost/test-2x.png 2x', 140 'http://localhost/test.png 1x, //localhost/test-2x.png 2x', 141 ), 142 array( 143 'path/to/test.png 1x, path/to/test-2x.png 2x', 144 'path/to/test.png 1x, path/to/test-2x.png 2x', 145 ), 146 ); 147 } 148 149 /** 150 * @ticket 29807 151 */ 152 function test_wp_filter_post_kses_picture() { 153 global $allowedposttags; 154 155 $html = '<picture><source srcset="pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; 156 $this->assertEquals( $html, wp_kses( $html, $allowedposttags ) ); 157 158 $html = '<picture><source srcset="https://wordpress.org/pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="https://wordpress.org/pear-tablet.jpeg 500w, https://wordpress.org/pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; 159 $this->assertEquals( $html, wp_kses( $html, $allowedposttags ) ); 160 161 // Test bad protocol in srcset 162 $original = '<picture><source srcset="bad://pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; 163 $expected = '<picture><source srcset="//pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; 164 $this->assertEquals( $expected, wp_kses( $original, $allowedposttags ) ); 165 } 166 167 function test_feed_links() { 168 global $allowedposttags; 81 169 $content = <<<EOF 82 170 <a href="feed:javascript:alert(1)">CLICK ME</a> 83 171 <a href="feed:javascript:feed:alert(1)">CLICK ME</a>
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)