Make WordPress Core


Ignore:
Timestamp:
12/21/2021 04:12:06 AM (3 years ago)
Author:
hellofromTonya
Message:

REST API: Support . in theme directory names in WP_REST_Global_Styles_Controller, WP_REST_Templates_Controller, and WP_REST_Themes_Controller.

Regex changes from [52376] are reverted to restore the original regex patterns. Why? [52376] used an include characters pattern, which was too limiting. It did not account for localized characters, such as é, or other valid directory name characters.

The original theme directory regex pattern, i.e. [^.\/]+(?:\/[^.\/]+)? excluded the period . character. Removing the . character resolves the reported issue by allowing matching for themes/theme-dirname-1.0/ or themes/<subdirname>/theme-dirname-1.0/.

As the pattern used an exclude approach, all characters are valid for matching except for /. However, not all characters are cross-platform valid for directory names. For example, the characters /:<>*?"| are not valid on Windows OS. The pattern now excludes those characters.

The theme's directory (or subdirectory) name pattern matching is now used in WP_REST_Global_Styles_Controller, WP_REST_Templates_Controller, and WP_REST_Themes_Controller.

Follow-up to [51003], [52051], [52275], [52376].

Props costdev, hellofromTonya, spacedmonkey, TimothyBlynJacobs, bijayyadav, kafleg.
Fixes #54596.

File:
1 edited

Legend:

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

    r52376 r52399  
    6969        register_rest_route(
    7070            $this->namespace,
    71             '/' . $this->rest_base . '/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)',
     71            // The route.
     72            sprintf(
     73                '/%s/(?P<id>%s%s)',
     74                $this->rest_base,
     75                // Matches theme's directory: `/themes/<subdirectory>/<theme>/` or `/themes/<theme>/`.
     76                // Excludes invalid directory name characters: `/:<>*?"|`.
     77                '([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)',
     78                // Matches the template name.
     79                '[\/\w-]+'
     80            ),
    7281            array(
    7382                'args'   => array(
     
    150159     */
    151160    public function _sanitize_template_id( $id ) {
    152         // Decode empty space.
    153161        $id = urldecode( $id );
    154162
Note: See TracChangeset for help on using the changeset viewer.