Opened 8 weeks ago
Last modified 2 weeks ago
#58132 new defect (bug)
Slashes used in block templates slug is a problem on Windows
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 6.2.3 | Priority: | normal |
Severity: | normal | Version: | 5.9 |
Component: | Editor | Keywords: | needs-testing-info reporter-feedback needs-unit-tests has-patch |
Focuses: | Cc: |
Description
Generally, they are all stored flat in the theme templates
or block-templates
folder; we have no problem here. But when they are stored deep under some folder/s, the slug checks won't pass on Windows.
This is because finding the template paths https://developer.wordpress.org/reference/functions/_get_block_templates_paths return backslashes \
and https://core.trac.wordpress.org/browser/tags/6.2/src/wp-includes/block-template-utils.php#L313 currently only does substr
extracts to come up with a slug that is passed to https://developer.wordpress.org/reference/functions/_build_block_template_result_from_file/, which eventually fails line https://core.trac.wordpress.org/browser/tags/6.2/src/wp-includes/block-template-utils.php#L981 as the slugs in the query are using forward slashes \
.
Attachments (5)
Change History (17)
#1
@
8 weeks ago
The fix here is just an easy str_replace
. Can be either at:
- directly to the actual check line
- up in the unified template object
#2
@
8 weeks ago
Hi!
Can you help by providing step-by-step testing instructions for reproducing the issues?
A similar problem did occur a few years ago, but it was supposedly fixed, so if it has re-appeared it is a regression.
Context: https://github.com/WordPress/gutenberg/issues/20375#issuecomment-686152426
#3
@
8 weeks ago
- Keywords needs-testing-info needs-testing reporter-feedback added
- Milestone changed from Awaiting Review to 6.2.1
Hi @gaft, welcome to Trac and thanks for opening this ticket and adding patches for consideration!
In addition to reproduction steps, we also need to verify whether this behaviour can be observed in WordPress 6.1, or if a regression was introduced in WordPress 6.2.
Milestoning for 6.2.1 for visibility.
#4
@
8 weeks ago
Hello, I am testing it now in version 6.2. Here are the quick steps to take:
- Create a page and assign to a custom template
wp_insert_post([
'post_status' => 'publish',
'post_type' => 'page',
'post_title' => 'Custom Template Page',
'meta_input' => [
'_wp_page_template' => 'deep/folder/test',
],
]);
- Add a template file named
test.html
in the theme undertemplates/deep/folder
custom-theme/ ├── parts/ ├── templates/ │ ├── deep/ │ │ └── folder/ │ │ └── test.html │ ├── 404.html │ ├── index.html │ └── page.html ├── screenshot.png ├── styles.css └── theme.json
- View the page at
/custom-template-page/
Currently, it only renders the templates/page.html
because https://core.trac.wordpress.org/browser/tags/6.2/src/wp-includes/block-template-utils.php#L981 evaluates to false
#5
@
8 weeks ago
- Component changed from General to Editor
- Keywords needs-testing removed
- Type changed from enhancement to defect (bug)
- Version changed from 6.2 to 5.9
I haven't spent too much time tracing this, but I think wp_normalize_path
would probably be a better fix than strpos
. I am exactly not sure where the fix would be, but I feel like it's higher up the chain than the current patch places it. I'm thinking perhaps the paths should be normalized in _get_block_templates_files
, but not 100% sure.
This looks like it might be [52062] that introduced the _get_block_templates_files
code, while [52247] abstracted the base paths into get_block_theme_folders
.
#6
@
7 weeks ago
I totally agree that wp_normalize_path
is a more robust function to use here. Also, I think it is best handled in _get_block_templates_files
where it can be useful elsewhere that expects slug to be in forward slashes.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
5 weeks ago
#8
@
5 weeks ago
- Keywords needs-unit-tests has-patch added
Patch 58132-3.diff
looks good, but we need to add some unit tests for this case.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
4 weeks ago
#10
@
4 weeks ago
Partially related: https://github.com/WordPress/gutenberg/issues/49100
Or—once this ticket is resolved, there may still be issues when trying to use /
in template IDs due to _sanitize_template_id()
.
directly to the actual check line