Changeset 47810
- Timestamp:
- 05/16/2020 07:01:49 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r47809 r47810 1382 1382 ) 1383 1383 ); 1384 } 1385 1386 if ( isset( $args['pattern'] ) ) { 1387 $pattern = str_replace( '#', '\\#', $args['pattern'] ); 1388 if ( ! preg_match( '#' . $pattern . '#u', $value ) ) { 1389 /* translators: 1: Parameter, 2: Pattern. */ 1390 return new WP_Error( 'rest_invalid_pattern', sprintf( __( '%1$s does not match pattern %2$s.' ), $param, $args['pattern'] ) ); 1391 } 1384 1392 } 1385 1393 } -
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r47809 r47810 728 728 ); 729 729 } 730 731 /** 732 * @ticket 44949 733 */ 734 public function test_string_pattern() { 735 $schema = array( 736 'type' => 'string', 737 'pattern' => '^a*$', 738 ); 739 740 $this->assertTrue( rest_validate_value_from_schema( 'a', $schema ) ); 741 $this->assertWPError( rest_validate_value_from_schema( 'b', $schema ) ); 742 } 743 744 /** 745 * @ticket 44949 746 */ 747 public function test_string_pattern_with_escaped_delimiter() { 748 $schema = array( 749 'type' => 'string', 750 'pattern' => '#[0-9]+', 751 ); 752 753 $this->assertTrue( rest_validate_value_from_schema( '#123', $schema ) ); 754 $this->assertWPError( rest_validate_value_from_schema( '#abc', $schema ) ); 755 } 756 757 /** 758 * @ticket 44949 759 */ 760 public function test_string_pattern_with_utf8() { 761 $schema = array( 762 'type' => 'string', 763 'pattern' => '^â{1}$', 764 ); 765 766 $this->assertTrue( rest_validate_value_from_schema( 'â', $schema ) ); 767 $this->assertWPError( rest_validate_value_from_schema( 'ââ', $schema ) ); 768 } 730 769 }
Note: See TracChangeset
for help on using the changeset viewer.