Skip to content

Improved namespace replacement logic when duplicating theme #777

@t-hamano

Description

@t-hamano

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions