Skip to content

Commit b46b855

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@55294 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9c4ddc2 commit b46b855

File tree

13 files changed

+157
-13
lines changed

13 files changed

+157
-13
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function register_routes() {
105105
// Excludes invalid directory name characters: `/:<>*?"|`.
106106
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)',
107107
// Matches the template name.
108-
'[\/\w-]+'
108+
'[\/\w%-]+'
109109
),
110110
array(
111111
'args' => array(
@@ -834,7 +834,7 @@ public function get_item_schema() {
834834
'context' => array( 'embed', 'view', 'edit' ),
835835
'required' => true,
836836
'minLength' => 1,
837-
'pattern' => '[a-zA-Z0-9_\-]+',
837+
'pattern' => '[a-zA-Z0-9_\%-]+',
838838
),
839839
'theme' => array(
840840
'description' => __( 'Theme identifier for the template.' ),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
/**
3+
* Block theme.
4+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
echo 'PHP template for page with ID 1';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- wp:paragraph -->
2+
<p>Small Header Template Part</p>
3+
<!-- /wp:paragraph -->

tests/phpunit/data/themedir1/block-theme-non-latin/parts/small-header-测试.html

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
Theme Name: Block Theme Non Latin
3+
Theme URI: https://wordpress.org/
4+
Description: Has different characters in theme directory name for testing purposes.
5+
Version: 0.0.1
6+
Text Domain: block-theme
7+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- wp:paragraph -->
2+
<p>(τεστ) Page Template</p>
3+
<!-- /wp:paragraph -->
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- wp:paragraph -->
2+
<p>(测试) Page Template</p>
3+
<!-- /wp:paragraph -->
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"version": 1,
3+
"settings": {
4+
"color": {
5+
"palette": [
6+
{
7+
"slug": "light",
8+
"name": "Light",
9+
"color": "#f5f7f9"
10+
},
11+
{
12+
"slug": "dark",
13+
"name": "Dark",
14+
"color": "#000"
15+
}
16+
],
17+
"gradients": [
18+
{
19+
"name": "Custom gradient",
20+
"gradient": "linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%)",
21+
"slug": "custom-gradient"
22+
}
23+
],
24+
"custom": false,
25+
"customGradient": false
26+
},
27+
"typography": {
28+
"fontSizes": [
29+
{
30+
"name": "Custom",
31+
"slug": "custom",
32+
"size": "100px"
33+
}
34+
],
35+
"customFontSize": false,
36+
"customLineHeight": true
37+
},
38+
"spacing": {
39+
"units": [
40+
"rem"
41+
],
42+
"customPadding": true
43+
},
44+
"blocks": {
45+
"core/paragraph": {
46+
"color": {
47+
"palette": [
48+
{
49+
"slug": "light",
50+
"name": "Light",
51+
"color": "#f5f7f9"
52+
}
53+
]
54+
}
55+
}
56+
}
57+
},
58+
"customTemplates": [
59+
{
60+
"name": "page-τεστ",
61+
"title": "Homepage template"
62+
},
63+
{
64+
"name": "page-测试",
65+
"title": "Homepage template"
66+
}
67+
],
68+
"templateParts": [
69+
{
70+
"name": "small-header-τεστ",
71+
"title": "Small Header",
72+
"area": "header"
73+
},
74+
{
75+
"name": "small-header-测试",
76+
"title": "Small Header",
77+
"area": "header"
78+
},
79+
]
80+
}

tests/phpunit/tests/rest-api/rest-schema-setup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ public function test_expected_routes_in_schema() {
146146
'/wp/v2/settings',
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',
152152
'/wp/v2/template-parts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',
153153
'/wp/v2/template-parts/lookup',
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',
159159
'/wp/v2/templates/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',

0 commit comments

Comments
 (0)