Make WordPress Core


Ignore:
Timestamp:
02/07/2023 11:45:18 PM (2 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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            ),
Note: See TracChangeset for help on using the changeset viewer.