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 -

Comments

leymannx created an issue. See original summary.

norman.lol’s picture

Initial patch added.

norman.lol’s picture

Status: Active » Needs review

Needs review

progzy’s picture

@leymannx thank you for the patch it helped me. However it does not work for some languages because of the "[a-z]{2}" in the regex. This is the case for Chinese for example (zh-hans).

norman.lol’s picture

Status: Needs review » Needs work

Ah yes, thanks for reporting. I didn't consider subtags.

progzy’s picture

Status: Needs work » Needs review
StatusFileSize
new809 bytes

I've uploaded an update of your patch.

thiagogomesverissimo’s picture

Status: Needs review » Reviewed & tested by the community

The pacth #3011276-6 worked for pt-br language.

norman.lol’s picture

Hide old patch

larowlan’s picture

Version: 8.6.x-dev » 8.8.x-dev
Issue tags: +Needs tests

As this is a bug, we need a test to go with it.

Thanks

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

norman.lol’s picture

What kind of test would be needed here? Where do we add it?

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jigarius’s picture

Though this works for me, I'm facing a strange issue which might or might not be related to this ticket.

drush config:get language.fr:views.view.blog display.default.display_options.title
# Returns: null because a French translation doesn't exist.
drush config:set language.fr:views.view.blog display.default.display_options.title 'Blogue'
# French translation is created as expected.
drush config:get language.fr:views.view.blog display.default.display_options.title
# Returns: Blogue
drush cache:rebuild
drush config:get language.fr:views.view.blog display.default.display_options.title
# Returns: null - I wonder why the translation is now gone.

Can anyone else reproduce this or know why this might be happening?

simgui8’s picture

Personally, #6 fixes the raised exception, but config table blob entry is not altered.

After clearing cache (and navigating to frontend), non-default collection updated config
reverts to the blob data in config table.

I have ended up db updating the data blob entry.

eddie_c’s picture

Status: Needs work » Needs review
StatusFileSize
new1.31 KB

Updated patch with test included

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

simgui8’s picture

After revisiting this one,
#18 fixes the problem

The problem was happening when doing a drush updb after upgrading from Drupal 9.2.9 to 9.2.10

Thanks!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs Review Queue Initiative, +Needs followup

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.

nikhil_110’s picture

StatusFileSize
new1.3 KB

Patch for 10.x

smustgrave’s picture

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

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.