weixin_39960145
weixin_39960145
2020-11-29 14:52

strtolower in Autoloader.php won't work using tr_TR locale

smarty is using strtolower in Autoload.php but have classes using capitalized "i", this won't work using the tr_TR.utf8 locale:


$ php -r 'var_dump(setlocale(LC_ALL, "tr_TR.utf-8")); echo strtolower("Smarty_Internal") . "\n";'
string(11) "tr_TR.utf-8"
smarty_Internal

Notice the still capitalized I.

Ensure you dpkg-reconfigure locales and install the "tr_TR.utf8" before doing the test, having "tr_TR.utf8" in the first lines shows that the setlocale worked, if you have bool(false), the setlocal did not change the locale so the strtolower test may wrongly succeed.

This happen because in their country they have dotted and undotted i, see: https://en.wikipedia.org/wiki/Dotted_and_dotless_I

该提问来源于开源项目:smarty-php/smarty

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39960145 weixin_39960145 5月前

    Also there's other places it won't work, like in loadPlugin, probably other places too.

    点赞 评论 复制链接分享
  • weixin_39914049 weixin_39914049 5月前

    Suggest using mb_strtolower instead if PHP is compiled with multibyte string function.

    点赞 评论 复制链接分享
  • weixin_39960145 weixin_39960145 5月前

    According to my git log, I tried (on Jan 6, the day I reported it), to use mb_strtolower, and it worked like a charm as I was having a site using the tr_TR locale at this time, so yes, it look like the right fix.

    点赞 评论 复制链接分享
  • weixin_39914049 weixin_39914049 5月前

    Great!!

    点赞 评论 复制链接分享
  • weixin_39580748 weixin_39580748 5月前

    I can confirm this issue still exists. I've beem doing a little debugging, but it seems we need to fix ucfirst too? Without fixing that I quickly run into errors in Smarty_Internal_TemplateCompilerBase::getTagCompiler. There are 40+ occurances throughout de codebase, so this might be somewhat dangerous to fix properly. There may be other upper-/lowercase conversions that need changing.

    I've been looking through a couple of bugreports on bugs.php.net and they don't sound encouraging: https://bugs.php.net/bug.php?id=18556

    Could you help in creating a PR and test it the tr_TR.utf8 locale? Remember to delete compiled templates regularly to trigger a fresh compile.

    点赞 评论 复制链接分享
  • weixin_39617113 weixin_39617113 5月前

    We've just run into this with https://github.com/pkp/ojs, which uses Smarty. In our own code, we resolved it with a special set of functions that are intended for "codesafe" uses (i.e. not locale dependent). See https://github.com/pkp/pkp-lib/blob/master/includes/functions.inc.php#L273..L281 for an example. I'd suggest a similar solution for calls to strtoupper, strtolower, ucfirst, etc. that operate on function/class names.

    点赞 评论 复制链接分享
  • weixin_39617113 weixin_39617113 5月前

    A proposed PR for this: https://github.com/smarty-php/smarty/pull/586

    点赞 评论 复制链接分享