gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Theme: Unable to update some default templates with hyphens

Open t-hamano opened this issue 3 years ago • 1 comments

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.html
  • onetwo-.html

File names that do not cause problems

  • one-two.html
  • one_two.html
  • one__two.html
  • _onetwo.html
  • onetwo_.html
  • one-_two.html
  • one_-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.html file.
  • 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-two template 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

t-hamano avatar Apr 16 '23 09:04 t-hamano

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

dhananjaykuber avatar Nov 17 '26 10:11 dhananjaykuber