polyfill icon indicating copy to clipboard operation
polyfill copied to clipboard

The Grapheme polyfill is failing tests when using `\X` as regex for clusters

Open stof opened this issue 1 year ago • 3 comments

See CI jobs for PHP 7.3+ which are failing a test when using the polyfill:

$this->assertSame('☎', grapheme_substr('☢☎❄', 1, 1));

\X does not split those as separate grapheme clusters.

stof avatar Dec 21 '24 18:12 stof

Apparently, the \X is correct only starting in PCRE 10.44: https://github.com/PCRE2Project/pcre2/issues/410

We might need to change our condition for the usage of the fallback regex.

stof avatar Dec 21 '24 19:12 stof

Yeah, it's only fixed in PCRE 10.44 (I was the one who reported). This is worked around in the proposed grapheme_str_split PR. I don't think there is a way to overcome this, apart from skipping the assertions on older PCRE2 versions.

Ayesh avatar Dec 21 '24 21:12 Ayesh

We already have some code dealing with that in https://github.com/symfony/polyfill/blob/a5ae13211e892f1b1e955f9a22d29eb1f9581c1f/src/Intl/Grapheme/Grapheme.php#L14

stof avatar Dec 21 '24 21:12 stof