update-countries.sh inadvertently broken by Issue #3328454

Created on 3 October 2024, 2 months ago
Updated 23 November 2024, 11 days ago

Problem/Motivation

While attempting to run the update-countries.sh script with an appropriate territories.json file, the resulting CountryManager.php file consisted of country codes mapped to t() verbatim (no country name within quotes) unlike the original CountryManager.php file provided with composer, which is correctly formatted.

This results in the country names being removed from the file and subsequent runs of update-countries.sh file to error on an invalid call to t() in CountryManager.php.

Steps to reproduce

Place the requested territories.json file in DRUPAL_ROOT and run core/scripts/update-countries.sh. The resulting core/lib/Drupal/Core/Locale/CountryManager.php will be "corrupted" with lines such as

'AC' => t(),

instead of

'AC' => t('Ascension Island'),

This was tested with PHP 8.3 and Drupal 10.3.5. The file appears to have the same bug in v11.x too.

Proposed resolution

Line 96 of core/scripts/update-countries.php needs to be changed from

$name = str_contains($name, '\'' ? '"' . $name . '"' : "'" . $name . "'");

to

$name = str_contains($name, '\'') ? '"' . $name . '"' : "'" . $name . "'";

Note the misplaced closing bracket inadvertently wrapping the entire ternary rather than just the two parameters to the str_contains function.

Remaining tasks

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

locale.module

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024