From fe00d7f7bf0b0f4609d1ffc2bc308c458ad67f0e Mon Sep 17 00:00:00 2001 From: TimothyBlynJacobs Date: Sat, 16 May 2020 19:03:08 +0000 Subject: [PATCH] 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 --- wp-includes/rest-api.php | 8 ++++++++ wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index 6c2e7b693b..cc600789f0 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -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'] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 306cf73786..f4866c9dee 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.