Changeset 48437
Legend:
- Unmodified
- Added
- Removed
-
trunk/package-lock.json
r48434 r48437 5940 5940 "kind-of": { 5941 5941 "version": "6.0.2", 5942 "resolved": "", 5942 "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", 5943 "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", 5943 5944 "dev": true 5944 5945 } … … 10567 10568 "kind-of": { 10568 10569 "version": "6.0.2", 10569 "resolved": "", 10570 "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", 10571 "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", 10570 10572 "dev": true 10571 10573 } … … 23585 23587 "kind-of": { 23586 23588 "version": "6.0.2", 23587 "resolved": "", 23589 "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", 23590 "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", 23588 23591 "dev": true 23589 23592 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php
r48069 r48437 71 71 return rest_validate_value_from_schema( $value, $schema ); 72 72 }, 73 'sanitize_callback' => static function ( $value, $request ) { 74 $block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] ); 75 76 if ( ! $block ) { 77 // This will get rejected in ::get_item(). 78 return true; 79 } 80 81 $schema = array( 82 'type' => 'object', 83 'properties' => $block->get_attributes(), 84 'additionalProperties' => false, 85 ); 86 87 return rest_sanitize_value_from_schema( $value, $schema ); 88 }, 73 89 ), 74 90 'post_id' => array( -
trunk/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
r48118 r48437 57 57 58 58 /** 59 * Dynamic block with boolean attributes block name. 60 * 61 * @since 5.5.0 62 * 63 * @var string 64 */ 65 protected static $dynamic_block_with_boolean_attributes_block_name = 'core/dynamic-block-with-boolean-attributes'; 66 67 /** 59 68 * Test API user's ID. 60 69 * … … 128 137 $this->register_post_context_test_block(); 129 138 $this->register_non_dynamic_block(); 139 $this->register_dynamic_block_with_boolean_attributes(); 130 140 parent::setUp(); 131 141 } … … 140 150 WP_Block_Type_Registry::get_instance()->unregister( self::$context_block_name ); 141 151 WP_Block_Type_Registry::get_instance()->unregister( self::$non_dynamic_block_name ); 152 WP_Block_Type_Registry::get_instance()->unregister( self::$dynamic_block_with_boolean_attributes_block_name ); 142 153 parent::tearDown(); 143 154 } … … 197 208 198 209 /** 210 * Registers the dynamic with boolean attributes block name. 211 * 212 * @since 5.5.0 213 */ 214 protected function register_dynamic_block_with_boolean_attributes() { 215 register_block_type( 216 self::$dynamic_block_with_boolean_attributes_block_name, 217 array( 218 'attributes' => array( 219 'boolean_true_attribute' => array( 220 'type' => 'boolean', 221 'default' => true, 222 ), 223 'boolean_false_attribute' => array( 224 'type' => 'boolean', 225 'default' => false, 226 ), 227 ), 228 'render_callback' => array( $this, 'render_test_block' ), 229 ) 230 ); 231 } 232 233 /** 199 234 * Test render callback. 200 235 * … … 524 559 525 560 /** 561 * @ticket 50620 562 */ 563 public function test_get_sanitized_attributes_for_dynamic_block_with_boolean_attributes() { 564 wp_set_current_user( self::$user_id ); 565 566 $request = new WP_REST_Request( 'GET', self::$rest_api_route . self::$dynamic_block_with_boolean_attributes_block_name ); 567 568 $attributes = array( 569 'boolean_true_attribute' => 'true', 570 'boolean_false_attribute' => 'false', 571 ); 572 573 $expected = array( 574 'boolean_true_attribute' => true, 575 'boolean_false_attribute' => false, 576 ); 577 578 $request->set_param( 'context', 'edit' ); 579 $request->set_param( 'attributes', $attributes ); 580 $response = rest_get_server()->dispatch( $request ); 581 $this->assertEquals( 200, $response->get_status() ); 582 $data = $response->get_data(); 583 584 $this->assertSame( $expected, json_decode( $data['rendered'], true ) ); 585 } 586 587 /** 526 588 * Get item schema. 527 589 *
Note: See TracChangeset
for help on using the changeset viewer.