php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61408 Character set failure
Submitted: 2012-03-15 20:14 UTC Modified: 2012-03-19 06:41 UTC
Votes:2
Avg. Score:2.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: inge at upandforward dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.3.5-1ubuntu7.7 OS: Linux Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: inge at upandforward dot com
New email:
PHP Version: OS:

 

 [2012-03-15 20:14 UTC] inge at upandforward dot com
Description:
------------
---
From manual page: http://www.php.net/function.basename#refsect1-function.basename-seealso
---
Even if I have defined setlocale('nb_NO.utf8");
the basename functions strips off some national characters.


Test script:
---------------
echo basename('/directory/Øving.png");

Expected result:
----------------
Øving.png

Actual result:
--------------
ving.png

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-15 21:28 UTC] cataphract@php.net
What's the return value of setlocale? Does locale -a show that locale?
 [2012-03-15 21:28 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2012-03-15 22:55 UTC] inge at upandforward dot com
-Status: Feedback +Status: Open -PHP Version: 5.3.10 +PHP Version: 5.3.5-1ubuntu7.7
 [2012-03-15 22:55 UTC] inge at upandforward dot com
There is no return value (it may be false or an empty string), and locale -a does not include "nb_NO". However, the site is used in Norway for Norwegian users, so it must be able to handle Norwegian characters. The basename function should not make such distinctions, so I have written my own - which works independently of locale or character set.
The php version has been corrected above because the bug report did not give that choice. My suggested replacement could not be uploaded because the site did not accept a text file, even if it stated that it was the only filetype accepted. I also had great trouble getting the right CAPTCHA (Oh, yes, I can add numbers! :) )
 [2012-03-15 23:01 UTC] inge at upandforward dot com
Here's a replacement, but without the $suffix parameter:

function IV_basename($name)
{	$name = strrchr($name,DIRECTORY_SEPARATOR);
	if ($name) return substr($name,1);
	return false;
}
 [2012-03-16 01:35 UTC] aharvey@php.net
There are encodings where 0x2f (/) and 0x5c (\) are valid bytes within multi-byte 
characters, so basename() has to be locale-aware to deal with that.

Fundamentally, I don't really see why you would expect basename() to be able to 
deal sensibly with a configured locale that you don't have installed. Your test 
script behaves fine provided nb_NO.utf8 is available.

Not a bug -> closing.
 [2012-03-16 01:35 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-03-16 10:07 UTC] inge at upandforward dot com
Comment found on stackoverflow.com:

"If you ask me, setlocale() sucks ass. I am a friend of managing this manually or using a library like Zend_Localeso you don't have to depend on locales being installed on the server (and sometimes still not working)".

The client should NOT be expected to use the same locale as the server, but if I could install the Norwegian locale, I think it might still be OK, So how do I install the above mentioned library, or some equivalent?
 [2012-03-19 00:23 UTC] aharvey@php.net
That's really a question for an Ubuntu support channel, but I think installing the 
language-support-nb package would do it.
 [2012-03-19 06:41 UTC] inge at upandforward dot com
Already installed! :)
Anyway, I thought that utf-8 was utf-8, regardless of locale. Oh well. I'll do with my work-around.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 08:01:23 2020 UTC