Bug #62119 [Com]: basename broken with non-ASCII-chars

From: Date: Thu, 25 May 2017 15:38:53 +0000
Subject: Bug #62119 [Com]: basename broken with non-ASCII-chars
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209258@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 Comment by: megaone at yandex dot ru Reported by: thomas dot hebinck at digionline dot de Summary: basename broken with non-ASCII-chars Status: Analyzed Type: Bug Package: *Directory/Filesystem functions Operating System: Linux/Ubuntu PHP Version: 5.3.13 Assigned To: cmb Block user comment: N Private report: N New Comment: "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' Previous Comments: ------------------------------------------------------------------------ [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&amp;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&amp;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 ------------------------------------------------------------------------ [2015-06-10 08:56:20] christiansen dot jacob at gmail dot com This is still an issue in PHP 5.6 and it is PHP's problem, since PHP roll its own implementation of basename. The problem seems to occur when running basename on a string that have a multibyte char as the first char when LC_TYPE is set to POSIX. Which seems to be default for PHP. On way to solve this is to set the LC_TYPE to UTF-8, but I guess that PHP should handle this. ------------------------------------------------------------------------ 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

« previous php.bugs (#209258) next »