Changeset 51908
- Timestamp:
- 10/15/2021 02:03:38 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r51657 r51908 2636 2636 * @since 5.5.0 Added the `$param` parameter. 2637 2637 * @since 5.6.0 Support the "anyOf" and "oneOf" keywords. 2638 * @since 5.9.0 Added `text-field` and `textarea-field` formats. 2638 2639 * 2639 2640 * @param mixed $value The value to sanitize. … … 2778 2779 case 'uuid': 2779 2780 return sanitize_text_field( $value ); 2781 2782 case 'text-field': 2783 return sanitize_text_field( $value ); 2784 2785 case 'textarea-field': 2786 return sanitize_textarea_field( $value ); 2780 2787 } 2781 2788 } -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r51568 r51908 24 24 array( 25 25 'args' => array( 26 'someinteger' => array(26 'someinteger' => array( 27 27 'type' => 'integer', 28 28 ), 29 'someboolean' => array(29 'someboolean' => array( 30 30 'type' => 'boolean', 31 31 ), 32 'somestring' => array(32 'somestring' => array( 33 33 'type' => 'string', 34 34 ), 35 'somehex' => array(35 'somehex' => array( 36 36 'type' => 'string', 37 37 'format' => 'hex-color', 38 38 ), 39 'someenum' => array(39 'someenum' => array( 40 40 'type' => 'string', 41 41 'enum' => array( 'a' ), 42 42 ), 43 'somedate' => array(43 'somedate' => array( 44 44 'type' => 'string', 45 45 'format' => 'date-time', 46 46 ), 47 'someemail' => array(47 'someemail' => array( 48 48 'type' => 'string', 49 49 'format' => 'email', 50 50 ), 51 'someuuid' => array(51 'someuuid' => array( 52 52 'type' => 'string', 53 53 'format' => 'uuid', 54 ), 55 'sometextfield' => array( 56 'type' => 'string', 57 'format' => 'text-field', 58 ), 59 'sometextareafield' => array( 60 'type' => 'string', 61 'format' => 'textarea-field', 54 62 ), 55 63 ), … … 217 225 'rest_invalid_uuid', 218 226 rest_validate_request_arg( '123e4567-e89b-12d3-a456-426655440000X', $this->request, 'someuuid' ) 227 ); 228 } 229 230 /** 231 * @ticket 49960 232 */ 233 public function test_validate_schema_format_text_field() { 234 $this->assertTrue( 235 rest_validate_request_arg( 'Hello World', $this->request, 'sometextfield' ) 236 ); 237 238 $this->assertErrorResponse( 239 'rest_invalid_type', 240 rest_validate_request_arg( false, $this->request, 'sometextfield' ) 241 ); 242 243 $this->assertSame( 244 'Hello World', 245 rest_sanitize_request_arg( 'Hello World', $this->request, 'sometextfield' ) 246 ); 247 $this->assertSame( 248 'Hello World', 249 rest_sanitize_request_arg( '<p>Hello World</p>', $this->request, 'sometextfield' ) 250 ); 251 } 252 253 /** 254 * @ticket 49960 255 */ 256 public function test_validate_schema_format_textarea_field() { 257 $this->assertTrue( 258 rest_validate_request_arg( "Hello\nWorld", $this->request, 'sometextareafield' ) 259 ); 260 261 $this->assertErrorResponse( 262 'rest_invalid_type', 263 rest_validate_request_arg( false, $this->request, 'sometextareafield' ) 264 ); 265 266 $this->assertSame( 267 "Hello\nWorld", 268 rest_sanitize_request_arg( "Hello\nWorld", $this->request, 'sometextareafield' ) 269 ); 270 $this->assertSame( 271 "Hello\nWorld", 272 rest_sanitize_request_arg( "<p>Hello\nWorld</p>", $this->request, 'sometextareafield' ) 219 273 ); 220 274 } … … 235 289 $this->assertArrayHasKey( 'somehex', $args ); 236 290 $this->assertArrayHasKey( 'someuuid', $args ); 291 $this->assertArrayHasKey( 'sometextfield', $args ); 292 $this->assertArrayHasKey( 'sometextareafield', $args ); 237 293 $this->assertArrayHasKey( 'someenum', $args ); 238 294 $this->assertArrayHasKey( 'someargoptions', $args ); … … 324 380 'somehex', 325 381 'someuuid', 382 'sometextfield', 383 'sometextareafield', 326 384 'someenum', 327 385 'someargoptions', … … 357 415 'somehex', 358 416 'someuuid', 417 'sometextfield', 418 'sometextareafield', 359 419 'someenum', 360 420 'someargoptions', -
trunk/tests/phpunit/tests/rest-api/rest-test-controller.php
r49246 r51908 37 37 'type' => 'object', 38 38 'properties' => array( 39 'somestring' => array(39 'somestring' => array( 40 40 'type' => 'string', 41 41 'description' => 'A pretty string.', … … 45 45 'context' => array( 'view' ), 46 46 ), 47 'someinteger' => array(47 'someinteger' => array( 48 48 'type' => 'integer', 49 49 'multipleOf' => 10, … … 54 54 'context' => array( 'view' ), 55 55 ), 56 'someboolean' => array(56 'someboolean' => array( 57 57 'type' => 'boolean', 58 58 'context' => array( 'view' ), 59 59 ), 60 'someurl' => array(60 'someurl' => array( 61 61 'type' => 'string', 62 62 'format' => 'uri', 63 63 'context' => array( 'view' ), 64 64 ), 65 'somedate' => array(65 'somedate' => array( 66 66 'type' => 'string', 67 67 'format' => 'date-time', 68 68 'context' => array( 'view' ), 69 69 ), 70 'someemail' => array(70 'someemail' => array( 71 71 'type' => 'string', 72 72 'format' => 'email', 73 73 'context' => array( 'view' ), 74 74 ), 75 'somehex' => array(75 'somehex' => array( 76 76 'type' => 'string', 77 77 'format' => 'hex-color', 78 78 'context' => array( 'view' ), 79 79 ), 80 'someuuid' => array(80 'someuuid' => array( 81 81 'type' => 'string', 82 82 'format' => 'uuid', 83 83 'context' => array( 'view' ), 84 84 ), 85 'someenum' => array( 85 'sometextfield' => array( 86 'type' => 'string', 87 'format' => 'text-field', 88 'context' => array( 'view' ), 89 ), 90 'sometextareafield' => array( 91 'type' => 'string', 92 'format' => 'textarea-field', 93 'context' => array( 'view' ), 94 ), 95 'someenum' => array( 86 96 'type' => 'string', 87 97 'enum' => array( 'a', 'b', 'c' ), 88 98 'context' => array( 'view' ), 89 99 ), 90 'someargoptions' => array(100 'someargoptions' => array( 91 101 'type' => 'integer', 92 102 'required' => true, … … 96 106 ), 97 107 ), 98 'somedefault' => array(108 'somedefault' => array( 99 109 'type' => 'string', 100 110 'enum' => array( 'a', 'b', 'c' ), … … 102 112 'default' => 'a', 103 113 ), 104 'somearray' => array(114 'somearray' => array( 105 115 'type' => 'array', 106 116 'items' => array( … … 112 122 'context' => array( 'view' ), 113 123 ), 114 'someobject' => array(124 'someobject' => array( 115 125 'type' => 'object', 116 126 'additionalProperties' => array(
Note: See TracChangeset
for help on using the changeset viewer.