Skip to content

[Intl] Erroneous numeric region codes available for usage #60696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llupa opened this issue Jun 4, 2025 · 1 comment · Fixed by #60711
Closed

[Intl] Erroneous numeric region codes available for usage #60696

llupa opened this issue Jun 4, 2025 · 1 comment · Fixed by #60711

Comments

@llupa
Copy link
Contributor

llupa commented Jun 4, 2025

Symfony version(s) affected

6.4

Description

The implementation of RegionDataGenerator has different standards for different data sets from ICU's data import. This results in inconsistent lists between

  • Regions
  • Alpha2ToAlpha3
  • Alpha3ToAlpha2
  • NumericToAlpha2

Regions

This is the first of the data sets to be pulled from ICU, it is in the end a translated list of Alpha2 country codes from localeBundle['Countries']. This is quiet good and does filter out certain code in the components's DENYLIST.

Alpha2ToAlpha3

This is the next data set that is pulled from ICU (via $metadataBundle['alias']['territory']) but filtered against Regions from above.

Alpha3ToAlpha2

The next data set. It is a simple array flip of Alpha3ToAlpha2, which makes it also filtered against Regions.

NumericToAlpha2

The last data set that is directly pulled from ICU (via $metadataBundle['alias']['territory']) but this time not filtered against Regions. This is turns makes it so that when using Countries and interacting with numeric lists, the following extra codes are available for usage (but not in the other 3 data sets):

Alpha‐2 CLDR Numeric Status Meaning/Use
AA 958 Unknown/Invalid Fallback when a region tag is not recognized.
QM 959 Reserved No real country; left for implementers’ own assignments.
QN 960 Reserved
QP 962 Reserved
QQ 963 Reserved
QR 964 Reserved
QS 965 Reserved
QT 966 Reserved
QV 968 Reserved
QW 969 Reserved
QX 970 Reserved
QY 971 Reserved
QZ 972 Reserved
XC 975 Private-Use User-assigned or testing‐only region codes.
XD 976 Private-Use
XE 977 Private-Use
XF 978 Private-Use
XG 979 Private-Use
XH 980 Private-Use
XI 981 Private-Use
XJ 982 Private-Use
XL 984 Private-Use
XM 985 Private-Use
XN 986 Private-Use
XO 987 Private-Use
XP 988 Private-Use
XQ 989 Private-Use
XR 990 Private-Use
XS 991 Private-Use
XT 992 Private-Use
XU 993 Private-Use
XV 994 Private-Use
XW 995 Private-Use
XX 996 Private-Use
XY 997 Private-Use
XZ 998 Private-Use

How to reproduce

Install the Intl component and simply dump the following data:

var_dump(Countries::getNumericCodes());

Possible Solution

The solution is to change the signature of the private function generateAlpha2ToNumericMapping so it is in line with the other functions that filter "territories" data against Regions (see above).

class RegionDataGenerator extends AbstractDataGenerator
{
    // ...
    private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessibleResourceBundle $metadataBundle): array
    {
        // ...
    }

    private function generateAlpha2ToNumericMapping(ArrayAccessibleResourceBundle $metadataBundle): array
    {
        // ...
    }
}

becomes

class RegionDataGenerator extends AbstractDataGenerator
{
    // ...
   private function generateAlpha2ToNumericMapping(array $countries, ArrayAccessibleResourceBundle $metadataBundle): array
    {
        // now check against countries and ignore codes reserved for the future or for private use
    }
}

My main question is if this is considered a BC break or not? I have the code to "fix" this ready, but I am not sure if it should go to Symfony 6.4, 7.4 or even 8.0?

Additional Context

No response

@ro0NL
Copy link
Contributor

ro0NL commented Jun 4, 2025

sounds reasonable for 7.4 IMHO 👍

we should probably add a test to check if the counts of all data sets are equal

nicolas-grekas added a commit that referenced this issue Jun 6, 2025
…odes (llupa)

This PR was merged into the 6.4 branch.

Discussion
----------

[Intl] Ensure data consistency between alpha and numeric codes

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #60696
| License       | MIT

Commits
-------

7d67017 [Intl] Ensure data consistency between alpha and numeric codes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants