REST API: Support the JSON Schema pattern keyword.

Props jason_the_adams, birgire, sorenbronsted.
Fixes #44949.

Built from https://develop.svn.wordpress.org/trunk@47810


git-svn-id: http://core.svn.wordpress.org/trunk@47586 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
TimothyBlynJacobs 2020-05-16 19:03:08 +00:00
parent 26bda18a23
commit fe00d7f7bf
2 changed files with 9 additions and 1 deletions

View File

@ -1382,6 +1382,14 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) {
)
);
}
if ( isset( $args['pattern'] ) ) {
$pattern = str_replace( '#', '\\#', $args['pattern'] );
if ( ! preg_match( '#' . $pattern . '#u', $value ) ) {
/* translators: 1: Parameter, 2: Pattern. */
return new WP_Error( 'rest_invalid_pattern', sprintf( __( '%1$s does not match pattern %2$s.' ), $param, $args['pattern'] ) );
}
}
}
if ( isset( $args['format'] ) ) {

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-47809';
$wp_version = '5.5-alpha-47810';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.