Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strings::toAscii returns empty string #107

Closed
hranicka opened this issue Apr 20, 2016 · 4 comments
Closed

Strings::toAscii returns empty string #107

hranicka opened this issue Apr 20, 2016 · 4 comments

Comments

@hranicka
Copy link
Contributor

hranicka commented Apr 20, 2016

When I run a PHP 7.0.3 CLI (Debian linux) application over SSH where I use Strings::webalize internally, I get empty strings as results in my nette-based app.

A found that problem is in Strings::toAscii implementation which is called from Strings::webalize.

Everything seems fine until iconv (glibc) call, this line.

Transliterator converts string correctly but iconv removes all of them.

When I replace iconv('UTF-8', 'WINDOWS-1250//TRANSLIT//IGNORE', $s) with iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s), I get an output (but incorrect, with a question mark (?) instead of some characters).

The line with iconv has error supressing @. So I get no error. When I remove it, I get PHP Notice: iconv(): Wrong charset, conversion from UTF-8 to WINDOWS-1250//TRANSLIT//IGNORE is not allowed.

Testing string: Koupil pojišťovnu a chce převrátit v Česku pojišťovnictví naruby, but same behaviour with everything. Output is an empty string also when input are ASCII characters only.


Maybe, in my CLI there is something wrong with php.ini configuration. Am I first who have this problem? Is the call of iconv correct?

Thank you for help.

@hranicka
Copy link
Contributor Author

php.ini:

iconv support => enabled
iconv implementation => glibc
iconv library version => 2.19
iconv.input_encoding => no value => no value
iconv.internal_encoding => no value => no value
iconv.output_encoding => no value => no value

nette/utils v2.3.8
nette/application v2.3.12

@hranicka
Copy link
Contributor Author

hranicka commented May 3, 2016

It seem that the problem is only on chrooted ssh accounts.
There php iconv works unexpected. Maybe related to https://bugs.php.net/bug.php?id=44096 (/usr/lib/gconv access).

Is the iconv call necessary when \Transliterator is available?

@xificurk
Copy link
Contributor

xificurk commented May 3, 2016

Is the iconv call necessary when \Transliterator is available?

Yes, it is... see #26 (comment)

@hranicka
Copy link
Contributor Author

hranicka commented May 3, 2016

@xificurk Thank you very much. Ok, iconv is required.


This issue is with chrooted accounts only and bad configuration.
It's not a bug in Nette\Utils.


I've fixed configuration on the server.
If you have the same problem and you have Jailkit on Linux, maybe helps this.

When I run iconv -l for non-chrooted account, I get large list of charsets.
But when I run it on chrooted account, I get only a few charsets.

So the problem is that iconv has no access for all charsets. Iconv in PHP nor system.

Edit Jailkit config like this:

# /etc/jailkit/jk_init.ini

[php]
comment = the php interpreter and libraries
executables = /usr/bin/php
directories = /usr/local/php
includesections = iconv # require iconv section for PHP

[iconv]
executables = /usr/bin/iconv # this is not required, but may helps with debug (i.e. iconv -l)
directories = /usr/lib/x86_64-linux-gnu/gconv # may be only /usr/lib/gconv

And reinit existing domains like this:

jk_init -c /etc/jailkit/jk_init.ini -f -k -j /var/www/clients/client1/web1 php

That's all, folks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants