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

Troubles with cyrillic label #218

Closed
pdum opened this issue Dec 12, 2012 · 8 comments
Closed

Troubles with cyrillic label #218

pdum opened this issue Dec 12, 2012 · 8 comments
Milestone

Comments

@pdum
Copy link

pdum commented Dec 12, 2012

When used in the Cyrillic label longer than 34 characters item is not displayed.
example: Доступ к управлению услуг регистратора домена

@lexa2
Copy link

lexa2 commented Dec 17, 2012

This one is extremely similar to Issue #210, i.e. it is due to inproper handling of the UTF-8 strings causing json_encode to choke on the illegal UTF-8 sequence and bail out returning empty JSON array to the AJAX frontend instead of meaningfull data. I've hit this one with a Description field being populated with a long enough cyrillic string.

In server logs one could notice a warning:

PHP Warning:  json_encode(): Invalid UTF-8 sequence in argument in /var/www/html/teampass/sources/i
tems.queries.php on line 2031

The cause is on the line 1892 of items.queries.php:

...
$html .= '&nbsp;<font size=2px>[' . strip_tags( stripslashes( substr( CleanString( $reccord['description'] ), 0, 30) ) ) . ']</font>';
...

To fix it, replace this line with one of the following, depending on your PHP configuration (i.e., use mb_substr if you've got mbstring module enabled or use iconv_substr if you've got iconv module active):

...
$html .= '&nbsp;<font size=2px>[' . strip_tags( stripslashes( mb_substr( CleanString( $reccord['description'] ), 0, 30, "UTF-8") ) ) . ']</font>';
...
...
$html .= '&nbsp;<font size=2px>[' . strip_tags( stripslashes( iconv_substr( CleanString( $reccord['description'] ), 0, 30, "UTF-8") ) ) . ']</font>';
...

@lexa2
Copy link

lexa2 commented Dec 17, 2012

Actually there's a bunch of other inproper uses of substr() in the items.queries.php which also should be fixed. In general I have to state that TeamPass is not safe for non-ASCII characters use it its current form.

@pdum
Copy link
Author

pdum commented Dec 17, 2012

Alexey thank you very much. Works good with this fix. I think we can replace all substr with mb_substr in items.queries.php for more stability?

@lexa2
Copy link

lexa2 commented Dec 17, 2012

Yep, it's what should be done at every place where PHP code deals with UTF-8 strings. Trouble is that with fresh PHP versions (5.0+) running on *nix hosts it might be better to use iconv_XX() funcs, while for Windows-based hosts and/or some *nix setups using mbstring mb_XX() funcs might be a more apropriate choice. For example, in my case mbstring module simply isn't available on the host i have TeamPass installed on (and I don't want to compile/install it as iconv serves my needs well).

@nilsteampassnet
Copy link
Owner

Very interesting post ... I'll try to think about a solution for that.

Thank you for reporting solution and explanations ;-)

@lexa2
Copy link

lexa2 commented Dec 20, 2012

You're welcome.

@vasilykolosov
Copy link

Had this problem too, fixed in my fork, and, as fair as I can see, Nils added it to the original. Try upgrading to the latest version, it does have the fix.

@vasilykolosov
Copy link

This commit: vasilykolosov@446df42

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

No branches or pull requests

4 participants