drush config:set for other than default collections raises exception

Created on 4 November 2018, almost 6 years ago
Updated 10 February 2023, over 1 year ago

Problem/Motivation

Trying to set language specific config, for example Spanish site name:

$ drush -y config:set language.es:system.site name "Hola Mundo"

Raises the following exception:

Invalid character in Config object name language.es:system.site.

Whereas the following two commands just work fine:

$ drush config:get language.es:system.site name
'language.es:system.site:name': 'Hello World'
$ drush -y config:set system.site name "Hello World"
 // Do you want to update name key in system.site config?: yes.

Proposed resolution

in core/lib/Drupal/Core/Config/ConfigBase.php inside public static function validateName($name) the following

    // The name must not contain any of the following characters:
    // : ? * < > " ' / \
    if (preg_match('/[:?*<>"\'\/\\\\]/', $name)) {
      throw new ConfigNameException("Invalid character in Config object name $name.");
    }

may better be

    // The name must not contain any of the following characters:
    // : ? * < > " ' / \
    // Except for language-specific collections.
    if (!preg_match('/^language.[a-z]{2}:/', $name)) {
      if (preg_match('/[:?*<>"\'\/\\\\]/', $name)) {
        throw new ConfigNameException("Invalid character in Config object name $name.");
      }
    }

to exclude at least language-specific collections from invalid character check. Although I'm not sure if it's not even better to make that a more general solution, for example if there are other collections than language collections. But are or can be there any other collections except language collections?

Remaining tasks

* patch provided
* reviews needed
* tests to be run
* documentation to be written

User interface changes

- None -

API changes

Unsure about that.

Data model changes

- None -

🐛 Bug report
Status

Needs work

Version

10.1

Component
Configuration 

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Confirmed this issue on Drupal 10.1 with a standard install
    With drush 11.
    Enabled german language.
    Think this will need a follow up: Installing the language did not default the site system for translation. Running the drush command kept giving

    [error]  Config language.de.site does not exist 
    

    Had to manually go to the site system page in my default language. Click translate and save the page before I could run the drush command

    After I did that the command worked.

    Just needs someone to opened that follow up.

  • 🇺🇸United States smustgrave

    Patch 18 applies to d10 just fine. Hiding 24 and removing credit for uploading the same patch. You can verify by clicking the test link under the patch.

    Also please include an interdiff with all patches may have helped show there is no difference

Production build 0.71.5 2024