Wrong result of strlen() with UTF-8 characters generates a validation error

MDD - September 10, 2007 - 19:58
Project:Content Construction Kit (CCK)
Version:5.x-1.6-1
Component:text.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:patch (code needs review)
Description

The designated maximum length text fields do not correspond to the actual, in the Russian charsets (UTF-8-general-ci).
It is less than three times. A English encoding no problems :(

Example: If I set a length field of 30 characters, it can enter only 10 (Russians charsets) or 30 English charsets.
After submitting forms error message exceeding the limit, which does not meet reality.

Thank you for your attention.

#1

magway@drupal.ru - September 11, 2007 - 20:52

Solution.
In function text_field() (file text.module) replace line
if (strlen($data['value']) > $field['max_length']) {
with
if (mb_strlen($data['value'],"UTF-8") > $field['max_length']) {
That seems to work.

#2

Shaltay - October 18, 2007 - 18:33

Hello.

Using drupal_strlen() seems to be a better solution

#3

tema - February 12, 2008 - 16:27
Title:Wrong permissible length text fields in the Russian character» Wrong result of strlen() with UTF-8 characters generates a validation error
Priority:normal» critical
Assigned to:MDD» Anonymous
Status:active» patch (code needs review)

The Russians are still not coming? Ok, here's a patch.

AttachmentSize
text_module_strlen.patch819 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.