Logic error in setlocale() when locales not fully present on system
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
php-gettext |
Fix Released
|
High
|
Данило Шеган |
Bug Description
While working with php-gettext in StatusNet, I noticed a problem with php-gettext's setlocale() check.
If setlocale() fails to return (say, due to the exact locale not being defined machine-wide), we fall back to checking LANG environment variable. When doing a *check* for the current locale instead of *setting* it, there was a logic error in this fallback and things didn't get initialized right.
This local patch has been working well for me; I think I submitted it to the old Savannah bug tracker but want to make sure it makes it into the new location. (And thanks again for updating the package -- it's hugely useful and my half-assed reimplementation from before I found it is nowhere near done :D)
Related branches
Changed in php-gettext: | |
status: | New → Triaged |
importance: | Undecided → High |
assignee: | nobody → Данило Шеган (danilo) |
Changed in php-gettext: | |
milestone: | none → 1.0.10 |
Changed in php-gettext: | |
status: | Fix Committed → Fix Released |
Brion, thanks for the report and a patch: sorry for not getting to it in the old tracker (I don't remember seeing it). I am not sure I fully understand the patch, though.
if ($ret and ($locale == '' or $locale == $ret))
seems mostly equivalent to what it is today:
if (($ret and $locale == '') or ($locale == $ret))
except when $ret is evaluated to false, and $locale == $ret (i.e. passed in $locale is same). I guess that can happen if you are passing $locale = ''. I'll look up through the setlocale() documentation and see when it can all return ''. I guess the right fix in that case would be to check for $ret == 0 (i.e. setlocale() has not been called).