Bug #62119 [Ana->Csd]: basename broken with non-ASCII-chars
| From: | phpdocbot@php.net | Date: | Fri, 07 Feb 2020 06:06:40 +0000 |
| Subject: | Bug #62119 [Ana->Csd]: basename broken with non-ASCII-chars | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225405@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62119&edit=1
ID: 62119
Updated by: phpdocbot@php.net
Reported by: thomas dot hebinck at digionline dot de
Summary: basename broken with non-ASCII-chars
-Status: Analyzed
+Status: Closed
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Linux/Ubuntu
PHP Version: 5.3.13
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=7e4167f3f2e202ba4463fbc3851e56067f085326
Log: Fix #62119: basename broken with non-ASCII-chars
Previous Comments:
------------------------------------------------------------------------
[2017-05-25 15:38:50] megaone at yandex dot ru
"On way to solve this is to set the LC_TYPE to UTF-8, but I guess that PHP should handle
this"
I'm actually having problem with UTF-8. What's more it's not just a single letter,
it's entire word that gets cut. So basically it cuts everything until any space. If no spaces
entire filename gets cut.
'Ð¸Ð¼Ñ Ñайла.txt' becomes ' Ñайла.txt'
'имÑÑайла.txt' becomes ' .txt'
------------------------------------------------------------------------
[2017-01-02 12:37:00] jeanseb@php.net
Automatic comment from SVN on behalf of jeanseb
Revision: http://svn.php.net/viewvc/?view=revision&revision=341589
Log: Related to #62119
This will do the same change for pathinfo and dirname as already made for basename.
--
Provided by anonymous 78971 (tobias.nyholm@gmail.com)
------------------------------------------------------------------------
[2016-10-14 17:28:13] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=340481
Log: Fix #62119: basename broken with non-ASCII-chars
We move the important notes up into the description section, and elevate
the note regarding the locale awareness to a caution.
------------------------------------------------------------------------
[2016-10-14 17:20:06] cmb@php.net
> This is still an issue in PHP 5.6 and it is PHP's problem, since
> PHP roll its own implementation of basename.
Yes. The actual culprit is that php_basename() uses mblen(3) if
available, and that is locale dependend. If an invalid character
is passed to mblen(3), -1 is returned, and the length is assumed
to be 1[1], what appears to be doubtful. Bailing out returning
FALSE, or at least a notice/warning might be more useful.
> On way to solve this is to set the LC_TYPE to UTF-8, but I guess
> that PHP should handle this.
As of November 2010 it is documented[1]:
| basename() is locale aware, so for it to see the correct
| basename with multibyte character paths, the matching locale
| must be set using the setlocale() function.
So clearly, setting the appropriate locale is the job of callers
of basename().
I'm going to move the notes up on the page, and will suggest
adding a notice/warning in case of unrecognized characters.
[1] <https://github.com/php/php-src/blob/PHP-7.0.12/ext/standard/string.c#L1531-L1532>
[2] <http://php.net/manual/en/function.basename.php#refsect1-function.basename-notes>
------------------------------------------------------------------------
[2016-10-14 16:31:00] cmb@php.net
Related To: Bug #67756
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=62119
--
Edit this bug report at https://bugs.php.net/bug.php?id=62119&edit=1