Default maxlength truncate algorithm has week place - even after truncating string can be longer than limit.
This is because javascript substr functions count new lines as one character not two as it have to be.

Example:
After we run obj.val().substr(0, 100) and then calculate string length with count = ml.twochar_lineending(obj.val()).length we could get count to be more that 100 (depends on how many new lines characters are found).

To fix this issue i have created patch - that will apply string truncation untill string will be no longer than limit taking into account new lines characters.

Note - i have created patch only for case when maxlength applied on simple textarea field, not WYSIWYG.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Eugene Fidelin’s picture

FileSize
670 bytes

Here is updated version of patch

seandunaway’s picture

Status: Needs review » Reviewed & tested by the community
seandunaway’s picture

Issue summary: View changes

change description

mpp’s picture

Version: 7.x-3.x-dev » 8.x-1.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

This bug now also occurs in Drupal 8.

cedewey’s picture

Status: Needs work » Closed (duplicate)

This is a duplicate of https://www.drupal.org/project/maxlength/issues/2825511 but perhaps some of the code here can be helpful in writing the patch for the other issue.