View Issue Details

IDProjectCategoryView StatusLast Update
0032385mantisbtbugtrackerpublic2023-10-31 16:32
Reporterdregad Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Target Version2.26.0Fixed in Version2.26.0 
Summary0032385: Incorrect use of mb_strimwidth() to truncate old/new values in history API
Description

0024056 and 0025002 introduced use of mb_strimwidth() to ensure that History API does not attempt to insert bigger data than the underlying old_value and new_value database columns can accept.

This works just fine with Western alphabets, but a string's width is NOT necessarily the same as its length. In Chinese, Japanese and Korean, some characters can be represented as full or half width, which may lead to unexpected results. In this case, if the string contains full-width chars, then it will be truncated to less than the expected 255 chars.

Example:

$s = 'スイス';                 # Original string (full-width katakana) - 9 bytes, 3 chars, width=6
echo mb_substr($s, 0, 3);     # スイス
echo mb_strimwidth($s, 0, 3); # ス
TagsNo tags attached.

Relationships

related to 0032365 closeddregad APPLICATION ERROR 401 when writing Custom Fields with more than 255 characters 
related to 0024056 closedatrol Custom Fields of type "Textarea" cannot contain more than 255 chars due to bug_history table 
related to 0025002 closedatrol Error when updating content in a custom field of type "Text Area" ("Textbereich"): History cannot be stored 

Activities

There are no notes attached to this issue.

Related Changesets

MantisBT: master 47a44b35

2023-04-12 13:32

dregad


Details Diff
New string_truncate() API function

Truncate a string to the specified length, optionally appending a
marker. This is intended to replace mb_strimwidth() calls when the
truncation should be driven by the string's length and not its width.

Issue 0032385
Affected Issues
0032385
mod - core/string_api.php Diff File

MantisBT: master fcb28a78

2023-04-12 13:34

dregad


Details Diff
Use new string_truncate() instead of mb_strimwidth()

This ensures that History API trunctates old_value and new_value to the
expected 255 chars even when full-width CJK symbols are used.

Fixes 0032385
Affected Issues
0032385
mod - core/history_api.php Diff File