Make WordPress Core

Changeset 56676


Ignore:
Timestamp:
09/25/2023 10:00:33 AM (7 months ago)
Author:
gziolo
Message:

REST API: Improve the block type schema for the name field

Align the schema between block.json defined in Gutenberg and the REST API endpoint for block types. It looks like the name field isn't validated in all places and when it uses pattern matching in the REST API code, then it was slightly different.

Props spacedmonkey, ockham.
See #59346.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php

    r56668 r56676  
    1616 */
    1717class WP_REST_Block_Types_Controller extends WP_REST_Controller {
     18
     19    const NAME_PATTERN = '^[a-z][a-z0-9-]*/[a-z][a-z0-9-]*$';
    1820
    1921    /**
     
    403405                        'description' => __( 'The name of the inner block.' ),
    404406                        'type'        => 'string',
     407                        'pattern'     => self::NAME_PATTERN,
     408                        'required'    => true,
    405409                    ),
    406410                    'attributes'  => array(
     
    480484                    'description' => __( 'Unique name identifying the block type.' ),
    481485                    'type'        => 'string',
    482                     'default'     => '',
     486                    'pattern'     => self::NAME_PATTERN,
     487                    'required'    => true,
    483488                    'context'     => array( 'embed', 'view', 'edit' ),
    484489                    'readonly'    => true,
     
    690695                    'type'        => array( 'array', 'null' ),
    691696                    'items'       => array(
    692                         'type' => 'string',
     697                        'type'    => 'string',
     698                        'pattern' => self::NAME_PATTERN,
    693699                    ),
    694700                    'default'     => null,
     
    700706                    'type'        => array( 'array', 'null' ),
    701707                    'items'       => array(
    702                         'type' => 'string',
     708                        'type'    => 'string',
     709                        'pattern' => self::NAME_PATTERN,
    703710                    ),
    704711                    'default'     => null,
     
    712719                    'type'              => 'object',
    713720                    'patternProperties' => array(
    714                         '^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+$' => array(
     721                        self::NAME_PATTERN => array(
    715722                            'type' => 'string',
    716723                            'enum' => array( 'before', 'after', 'first_child', 'last_child' ),
Note: See TracChangeset for help on using the changeset viewer.