Changeset 64355
- Timestamp:
- 10/15/2026 08:08:11 AM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-bindings/render.php
r64233 r64355 183 183 public function data_different_get_value_callbacks() { 184 184 return array( 185 'pass arguments to source' => array(185 'pass arguments to source' => array( 186 186 function ( $source_args, $block_instance, $attribute_name ) { 187 187 $value = $source_args['key']; … … 190 190 "<p class=\"wp-block-paragraph\">The attribute name is 'content' and its binding has argument 'key' with value 'test'.</p>", 191 191 ), 192 'unsafe HTML should be sanitized' => array(193 function () {194 return '<script>alert("Unsafe HTML")</script>';195 },196 '<p class="wp-block-paragraph"></p>',197 ),198 192 'symbols and numbers should be rendered correctly' => array( 199 193 function () { … … 241 235 'The block content should be updated with the value returned by the source.' 242 236 ); 237 } 238 239 /** 240 * Tests that unsafe HTML returned by the source is sanitized. 241 * 242 * @ticket 60651 243 * @ticket 66208 244 * 245 * @covers ::register_block_bindings_source 246 */ 247 public function test_unsafe_html_from_source_is_sanitized() { 248 register_block_bindings_source( 249 self::SOURCE_NAME, 250 array( 251 'label' => self::SOURCE_LABEL, 252 'get_value_callback' => function () { 253 return '<script>alert("Unsafe HTML")</script>'; 254 }, 255 ) 256 ); 257 258 $block_content = <<<HTML 259 <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source"}}}} --> 260 <p>This should not appear</p> 261 <!-- /wp:paragraph --> 262 HTML; 263 $parsed_blocks = parse_blocks( $block_content ); 264 $block = new WP_Block( $parsed_blocks[0] ); 265 $result = $block->render(); 266 267 $processor = new WP_HTML_Tag_Processor( $result ); 268 $this->assertFalse( $processor->next_tag( 'SCRIPT' ), 'The SCRIPT element should be removed.' ); 243 269 } 244 270
Note:
See TracChangeset
for help on using the changeset viewer.