Bug #79617 [Nab]: mb_convert_case() with MB_CASE_TITLE unexpected behavior for second characters
| From: | nikic@php.net | Date: | Thu, 21 May 2020 19:59:41 +0000 |
| Subject: | Bug #79617 [Nab]: mb_convert_case() with MB_CASE_TITLE unexpected behavior for second characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227119@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79617&edit=1
ID: 79617
Updated by: nikic@php.net
Reported by: dedienaar+phpnet at gmail dot com
Summary: mb_convert_case() with MB_CASE_TITLE unexpected
behavior for second characters
Status: Not a bug
Type: Bug
Package: *Unicode Issues
Operating System: Ubuntu 18.04.4 LTS
PHP Version: 7.2.31
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
For reference, the relevant fix in 7.3 was https://github.com/php/php-src/commit/f4a1d9c8211fa7878af14d0bd94b2deaab19ae21.
Previous Comments:
------------------------------------------------------------------------
[2020-05-21 19:52:31] nikic@php.net
I rewrote title case folding in PHP 7.3, and as far as I can see everything folds correctly there:
https://3v4l.org/8I587
Please use a recent version of PHP.
------------------------------------------------------------------------
[2020-05-21 18:09:46] girgias@php.net
I'm assigning this to Nikita just to double check but this seems to me not be a bug.
Copy pasting the character which you are indicating to be a quotation mark (in which case it should
indeed capitalize the first letter) into google I come up with the code point for "Modifier
Letter Right Half Ring" (U+02BE) which is not a quotation mark and is meant to modify the
previous code-point.
Thus the string is not valid UTF-8 from what my limited knowledge about it. And the behaviour is
totally expected.
Moreover, a single apostrophe/quotation mark MUST NOT capitalize the letter after it otherwise we
would get stupid text such as "Isn'T valid" which is and should be
"Isn't"
The backtick follows the same principle you can't just have a single one and expect it to
recognize it as a possible quotation mark (which is already highly debatable)
------------------------------------------------------------------------
[2020-05-21 17:41:09] dedienaar+phpnet at gmail dot com
Description:
------------
This relates to:
- https://www.php.net/manual/en/function.mb-convert-case
- https://github.com/php/php-src/blob/35e0a91db717fe441a89ca9554d8843d8ee63112/ext/mbstring/mbstring.c#L2674-L2709
- https://github.com/laravel/framework/issues/32910
The function
mb_convert_case() unfortunately does not take apostrophes, quotes and
certain other special characters into consideration when converting case using
MB_CASE_TITLE.
Test script:
---------------
>>> var_dump(mb_convert_case('al-fÄtiḥah', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(13) "Al-FÄtiḥah" // <-- GOOD
>>> var_dump(mb_convert_case('AL-FÄTIḤAH', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(13) "Al-FÄtiḥah" // <-- GOOD
>>> var_dump(mb_convert_case('ʾÄli-Ê¿imrÄn', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(15) "ʾÄli-Ê¿imrÄn" // <-- NOT GOOD: Not uppercased
'Ä' and 'I' due to preceding ʾ and Ê¿
>>> var_dump(mb_convert_case('ʾÄLI-Ê¿IMRÄN', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(15) "ʾÄli-Ê¿imrÄn" // <-- NOT GOOD: Lowercased 'Ä'
and 'I' due to preceding ʾ and ʿ
>>> var_dump(mb_convert_case('aá¹£-á¹£ÄffÄt', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(15) "Aá¹£-á¹¢ÄffÄt" // GOOD
>>> var_dump(mb_convert_case('Aá¹¢-á¹¢ÄFFÄT', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(15) "Aá¹£-á¹¢ÄffÄt" // GOOD
>>> var_dump(mb_convert_case('á¹Äʾ hÄʾ', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(13) "ṬÄʾ HÄʾ" // GOOD
>>> var_dump(mb_convert_case('ṬÄʾ HÄʾ', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(13) "ṬÄʾ HÄʾ" // GOOD
>>> var_dump(mb_convert_case('ʾibrÄhÄ«m', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(11) "ʾibrÄhÄ«m" // <-- NOT GOOD: Lowercased 'I' due to
preceding ʾ
>>> var_dump(mb_convert_case('ʾIBRÄHĪM', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(11) "ʾibrÄhÄ«m" // <-- NOT GOOD: Lowercased 'I' due to
preceding ʾ
>>> var_dump(mb_convert_case('\'ibrÄhÄ«m', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(10) "'ibrÄhÄ«m" // <-- NOT GOOD: Lowercased 'I' due to
preceding apostrophe
>>> var_dump(mb_convert_case('`ibrÄhÄ«m', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(10) "`ibrÄhÄ«m" // <-- NOT GOOD: Lowercased 'I' due to
preceding backtick
>>> var_dump(mb_convert_case('"ibrÄhÄ«m', MB_CASE_TITLE,
>>> 'UTF-8'));
=> string(10) ""ibrÄhÄ«m" // <-- Wrongly lowercased 'I' due to
preceding quote
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79617&edit=1