Theme: Unable to update some default templates with hyphens
Description
You can define default templates by placing files in the theme's templates directory. I have found that some patterns with hyphens in the filenames do not save the content correctly in the site editor.
I have confirmed that this problem occurs in the following patterns. If an underscore is used instead of a hyphen, it will not be reproduced.
- Consecutive hyphens
- Hyphens are used at the beginning or at the end
File names that cause problems
one--two.html-onetwo.htmlonetwo-.html
File names that do not cause problems
one-two.htmlone_two.htmlone__two.html_onetwo.htmlonetwo_.htmlone-_two.htmlone_-two.html
The content will not be saved correctly, but will be created as a new template with a new slug. For example, updating a template named one--two will add a new template named one-two.
Step-by-step reproduction instructions
- Enable Emptytheme included in the Gutenberg repository.
- Create a
test/emptytheme/templates/one--two.htmlfile. - Open the template.
- Make changes to the template and save it (no error occurs).
- Reload the page (a message appears warning that the content will not be saved).
- Updated content will be lost.
- If you check the template list, you will see that a new
one-twotemplate has been created.
Screenshots, screen recording, code snippet
https://user-images.githubusercontent.com/54422211/232291214-86346a75-ef9a-4f35-b1f8-06e8f391262f.mp4
Environment info
- WordPress Version: WordPress 6.3-alpha-55651
- Gutenberg Version: 15.6.0-rc.1
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
I reproduced this on trunk (7.2-beta2): saving one--two returns a different template (one-two), both are listed, and resolving it on the front end triggers an Undefined array key warning. The fix is in core, so I opened Trac #66714 with a PR: https://github.com/WordPress/wordpress-develop/pull/16060