Changeset 47753
- Timestamp:
- 05/03/2020 07:18:40 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r47627 r47753 1392 1392 /* translators: %s: IP address. */ 1393 1393 return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $param ) ); 1394 } 1395 break; 1396 case 'uuid': 1397 if ( ! wp_is_uuid( $value ) ) { 1398 /* translators: %s is the name of a JSON field expecting a valid uuid. */ 1399 return new WP_Error( 'rest_invalid_uuid', sprintf( __( '%s is not a valid UUID.' ), $param ) ); 1394 1400 } 1395 1401 break; … … 1550 1556 case 'ip': 1551 1557 return sanitize_text_field( $value ); 1558 1559 case 'uuid': 1560 return sanitize_text_field( $value ); 1552 1561 } 1553 1562 } -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r47511 r47753 44 44 'format' => 'email', 45 45 ), 46 'someuuid' => array( 47 'type' => 'string', 48 'format' => 'uuid', 49 ), 46 50 ), 47 51 ) … … 202 206 'rest_invalid_date', 203 207 rest_validate_request_arg( '2010-18-18T12:00:00', $this->request, 'somedate' ) 208 ); 209 } 210 211 /** 212 * @ticket 50053 213 */ 214 public function test_validate_schema_format_uuid() { 215 $this->assertTrue( 216 rest_validate_request_arg( '123e4567-e89b-12d3-a456-426655440000', $this->request, 'someuuid' ) 217 ); 218 219 $this->assertErrorResponse( 220 'rest_invalid_uuid', 221 rest_validate_request_arg( '123e4567-e89b-12d3-a456-426655440000X', $this->request, 'someuuid' ) 204 222 ); 205 223 } … … 246 264 'someemail', 247 265 'somehex', 266 'someuuid', 248 267 'someenum', 249 268 'someargoptions', … … 276 295 'someemail', 277 296 'somehex', 297 'someuuid', 278 298 'someenum', 279 299 'someargoptions', -
trunk/tests/phpunit/tests/rest-api/rest-schema-sanitization.php
r47450 r47753 91 91 } 92 92 93 /** 94 * @ticket 50053 95 */ 96 public function test_format_uuid() { 97 $schema = array( 98 'type' => 'string', 99 'format' => 'uuid', 100 ); 101 $this->assertEquals( '44', rest_sanitize_value_from_schema( 44, $schema ) ); 102 $this->assertEquals( 'hello', rest_sanitize_value_from_schema( 'hello', $schema ) ); 103 $this->assertEquals( 104 '123e4567-e89b-12d3-a456-426655440000', 105 rest_sanitize_value_from_schema( '123e4567-e89b-12d3-a456-426655440000', $schema ) 106 ); 107 } 108 93 109 public function test_type_array() { 94 110 $schema = array( -
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r47627 r47753 84 84 $this->assertTrue( rest_validate_value_from_schema( '#FFF', $schema ) ); 85 85 $this->assertWPError( rest_validate_value_from_schema( 'WordPress', $schema ) ); 86 } 87 88 /** 89 * @ticket 50053 90 */ 91 public function test_format_uuid() { 92 $schema = array( 93 'type' => 'string', 94 'format' => 'uuid', 95 ); 96 $this->assertTrue( rest_validate_value_from_schema( '123e4567-e89b-12d3-a456-426655440000', $schema ) ); 97 $this->assertWPError( rest_validate_value_from_schema( '123e4567-e89b-12d3-a456-426655440000X', $schema ) ); 98 $this->assertWPError( rest_validate_value_from_schema( '123e4567-e89b-?2d3-a456-426655440000', $schema ) ); 86 99 } 87 100 -
trunk/tests/phpunit/tests/rest-api/rest-test-controller.php
r47450 r47753 70 70 'context' => array( 'view' ), 71 71 ), 72 'someuuid' => array( 73 'type' => 'string', 74 'format' => 'uuid', 75 'context' => array( 'view' ), 76 ), 72 77 'someenum' => array( 73 78 'type' => 'string',
Note: See TracChangeset
for help on using the changeset viewer.