When using TextLine Field Typewith set a maximum number of characters, it is actually checking a number of bytes instead of a number of characters. This means that strings with multi-byte characters can in some cases not be validated correctly. For example string "Tęst" will not pass the validation when the maximum characters allowed for that field is 4.
This issue exists in eZ Platform UI and also in Public API for both eZ Platform and eZ Publish. It doesn't exist in Legacy Admin.
This issue is caused by using strlen() function instead of mb_strlen (for example here: https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Publish/Core/FieldType/TextLine/Type.php#L108). TextLine Field Type is possibly not the only one affected. Also, possibly other functions (like strpos or strstr) should be changed to their multi-byte safe counterparts to avoid other similar errors.
Steps to reproduce for eZ Platform
- Create new eZ Platform installation.
- In Platform UI, navigate to "Admin Panel"/"Content types"/"Content" Content Type Group.
- There, create a new Content Type with any name and identifier.
- Add one Content Field Type to the freshly created Content Type of type TextLine (ezstring) and set its Maximum length to 4 and name it "Title".
- Navigate to "Content"/"Content structure". In "eZ Platform" Folder, create a new Content Object of the Type you have created in previous steps. In the "Title" field, enter "Tęst" or similar string with 4 characters and at least one multi-byte character.
- Click "Save" button. You will be presented with the error "An error occurred while publishing the draft".
Steps to reproduce for eZ Publish
- Create new eZ Publish installation.
- In Legacy Admin, navigate to "Setup"/"Classes"/"Content" Class Group.
- There, create a new Class with any name and identifier.
- Add one Attribute to the freshly created Class of type Text line (ezstring) and set its Maximum length to 4 and name it "Title".
- Navigate to "Content structure". In "Home" Landing Page, create a new Content of the Class you have created in previous steps. In the "Title" field, enter "Tęst" or similar string with 4 characters and at least one multi-byte character.
- Click "Send for publishing". The Content will be successfully created.
- Now, in your project, create a new Symfony Command TestCommand.php with the following code (change $contentId from 66 to your created object's Object ID):
- Execute the command by running the following in your console:
You will be presented with the error "Content fields did not validate".