Make WordPress Core

Changeset 55294


Ignore:
Timestamp:
02/07/2023 11:45:18 PM (4 years ago)
Author:
danielbachhuber
Message:

REST API: Support non-Latin characters in template route regex.

Non-Latin characters are URL-encoded (e.g. %cf%84%ce%b5%cf%83%cf%84). Matching % in the route ensures templates with non-Latin titles can be properly saved.

Props antonyagrios, mburridge.
Fixes #57329.

Location:
trunk
Files:
11 added
5 edited

Legend:

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

    r54817 r55294  
    106106                                '([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)',
    107107                                // Matches the template name.
    108                                 '[\/\w-]+'
     108                                '[\/\w%-]+'
    109109                        ),
    110110                        array(
     
    835835                                        'required'    => true,
    836836                                        'minLength'   => 1,
    837                                         'pattern'     => '[a-zA-Z0-9_\-]+',
     837                                        'pattern'     => '[a-zA-Z0-9_\%-]+',
    838838                                ),
    839839                                'theme'          => array(
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r55029 r55294  
    147147                        '/wp/v2/template-parts',
    148148                        '/wp/v2/template-parts/(?P<id>[\d]+)/autosaves',
    149                         '/wp/v2/template-parts/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+)',
     149                        '/wp/v2/template-parts/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)',
    150150                        '/wp/v2/template-parts/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)',
    151151                        '/wp/v2/template-parts/(?P<parent>[\d]+)/revisions',
     
    154154                        '/wp/v2/templates',
    155155                        '/wp/v2/templates/(?P<id>[\d]+)/autosaves',
    156                         '/wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+)',
     156                        '/wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)',
    157157                        '/wp/v2/templates/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)',
    158158                        '/wp/v2/templates/(?P<parent>[\d]+)/revisions',
  • trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php

    r54402 r55294  
    6767                );
    6868                $this->assertArrayHasKey(
    69                         '/wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+)',
     69                        '/wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)',
    7070                        $routes,
    7171                        'Single template based on the given ID route does not exist'
     
    293293                                        'post_content' => file_get_contents( $theme_root_dir . 'block-theme/templates/page-home.html' ),
    294294                                        'post_excerpt' => 'Description of page home template.',
     295                                ),
     296                        ),
     297                        'template parts: parent theme with non latin characters' => array(
     298                                'theme_dir' => 'themedir1/block-theme-non-latin',
     299                                'template'  => 'small-header-%cf%84%ce%b5%cf%83%cf%84',
     300                                'args'      => array(
     301                                        'post_name'    => 'small-header-τεστ',
     302                                        'post_title'   => 'Small Header τεστ Template',
     303                                        'post_content' => file_get_contents( $theme_root_dir . '/block-theme-non-latin/parts/small-header-τεστ.html' ),
     304                                        'post_excerpt' => 'Description of small header τεστ template.',
     305                                ),
     306                        ),
     307                        'template: parent theme with non latin name'  => array(
     308                                'theme_dir' => 'themedir1/block-theme-non-latin',
     309                                'template'  => 'page-%cf%84%ce%b5%cf%83%cf%84',
     310                                'args'      => array(
     311                                        'post_name'    => 'page-τεστ',
     312                                        'post_title'   => 'τεστ Page Template',
     313                                        'post_content' => file_get_contents( $theme_root_dir . 'block-theme-non-latin/templates/page-τεστ.html' ),
     314                                        'post_excerpt' => 'Description of page τεστ template.',
     315                                ),
     316                        ),
     317                        'template parts: parent theme with chinese characters' => array(
     318                                'theme_dir' => 'themedir1/block-theme-non-latin',
     319                                'template'  => 'small-header-%e6%b5%8b%e8%af%95',
     320                                'args'      => array(
     321                                        'post_name'    => 'small-header-测试',
     322                                        'post_title'   => 'Small Header 测试 Template',
     323                                        'post_content' => file_get_contents( $theme_root_dir . '/block-theme-non-latin/parts/small-header-测试.html' ),
     324                                        'post_excerpt' => 'Description of small header 测试 template.',
     325                                ),
     326                        ),
     327                        'template: parent theme with non latin name using chinese characters' => array(
     328                                'theme_dir' => 'themedir1/block-theme-non-latin',
     329                                'template'  => 'page-%e6%b5%8b%e8%af%95',
     330                                'args'      => array(
     331                                        'post_name'    => 'page-测试',
     332                                        'post_title'   => '测试 Page Template',
     333                                        'post_content' => file_get_contents( $theme_root_dir . 'block-theme-non-latin/templates/page-测试.html' ),
     334                                        'post_excerpt' => 'Description of page 测试 template.',
    295335                                ),
    296336                        ),
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r55133 r55294  
    182182                        'Block Theme Child Theme With Fluid Typography',
    183183                        'Block Theme Child Theme With Fluid Typography Config',
     184                        'Block Theme Non Latin',
    184185                        'Block Theme [0.4.0]',
    185186                        'Block Theme [1.0.0] in subdirectory',
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r55248 r55294  
    51065106                            "type": "string",
    51075107                            "minLength": 1,
    5108                             "pattern": "[a-zA-Z0-9_\\-]+",
     5108                            "pattern": "[a-zA-Z0-9_\\%-]+",
    51095109                            "required": true
    51105110                        },
     
    52485248            }
    52495249        },
    5250         "/wp/v2/templates/(?P<id>([^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)[\\/\\w-]+)": {
     5250        "/wp/v2/templates/(?P<id>([^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)[\\/\\w%-]+)": {
    52515251            "namespace": "wp/v2",
    52525252            "methods": [
     
    52975297                            "type": "string",
    52985298                            "minLength": 1,
    5299                             "pattern": "[a-zA-Z0-9_\\-]+",
     5299                            "pattern": "[a-zA-Z0-9_\\%-]+",
    53005300                            "required": false
    53015301                        },
     
    56115611                            "type": "string",
    56125612                            "minLength": 1,
    5613                             "pattern": "[a-zA-Z0-9_\\-]+",
     5613                            "pattern": "[a-zA-Z0-9_\\%-]+",
    56145614                            "required": false
    56155615                        },
     
    57905790                            "type": "string",
    57915791                            "minLength": 1,
    5792                             "pattern": "[a-zA-Z0-9_\\-]+",
     5792                            "pattern": "[a-zA-Z0-9_\\%-]+",
    57935793                            "required": true
    57945794                        },
     
    59375937            }
    59385938        },
    5939         "/wp/v2/template-parts/(?P<id>([^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)[\\/\\w-]+)": {
     5939        "/wp/v2/template-parts/(?P<id>([^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)[\\/\\w%-]+)": {
    59405940            "namespace": "wp/v2",
    59415941            "methods": [
     
    59865986                            "type": "string",
    59875987                            "minLength": 1,
    5988                             "pattern": "[a-zA-Z0-9_\\-]+",
     5988                            "pattern": "[a-zA-Z0-9_\\%-]+",
    59895989                            "required": false
    59905990                        },
     
    63056305                            "type": "string",
    63066306                            "minLength": 1,
    6307                             "pattern": "[a-zA-Z0-9_\\-]+",
     6307                            "pattern": "[a-zA-Z0-9_\\%-]+",
    63086308                            "required": false
    63096309                        },
Note: See TracChangeset for help on using the changeset viewer.