-
Notifications
You must be signed in to change notification settings - Fork 60
Description
When cloning a theme, we replace namespaces based on the theme name you enter.
However, in the current implementation, there have been many reported cases where incorrect code was generated as a result of the replacement. Theme names that can cause problems include symbols, non-Latin characters, emojis, numbers, etc.
The code generated from this theme name can cause critical errors by generating invalid function names, namespaces, variable names, etc. This issue does not only occur with PHP, but can occur with any file extension that is considered eligible for replacement.
Examples of reported issues:
- Clone: New theme name is used in block names #332
- Bug: Themes with names that start with digits cause PHP errors #503
- PHP Namespaces in functions.php can lead to fatal error #733
- Using "&" in the name breaks the namespace generation #772
In #503, two ideas are proposed to get around this issue:
- Validate the theme name and not allow them to start with digits
- Sanitize the theme name in a way that makes sure it's a valid PHP function prefix
The code and formatting that is considered invalid vary depending on the file extension. Let's explore what the best approach is.