Hey -

Due to the way strlen (and mb_strlen) work, line breaks count as two characters in PHP, but not in Javascript. This can lead to confusion for users who type right up to the limit, hit submit, and then get an error that it's too long, even though the Javascript counter doesn't think so.

One way to fix this would be to change line 248 of maxlength.module from:

          if (drupal_strlen($node->$field) > $limit) {

to:

          if (drupal_strlen(str_replace("\r\n", "\n", $node->$field)) > $limit) {

However, I'm not sure what the performance implications might be. There's a couple of other places where drupal_strlen is called that could also be changed, but at a quick glance, it doesn't appear that they need to be, strictly speaking.

What do you think, and should I submit a patch for this? Is there another, better way to handle this?

Isaac

Comments

nickrice’s picture

I'm also hitting this issue.

It gives the impression to the user that the field isn't working at all as deleting several characters "just in case" doesn't work if there are a number of line breaks.

nickrice’s picture

Version: 6.x-2.0-beta1 » 6.x-2.0-beta2

(Moving version to 6.x-2-beta2 as still an issue there)

nickrice’s picture

Priority: Normal » Major

I think I might have got confused about this and am seeing a different issue.

I'm getting the same effect on CCK textareas where the length as the back end sees it is one longer per carriage return than the module thinks.

nickrice’s picture

Version: 6.x-2.0-beta2 » 6.x-2.0-beta1
Priority: Major » Normal

Ahhhhhh

Forget I spoke!

I realise I've just turned this into a duplicate of http://drupal.org/node/623120

Reverting everything back to what it was to start with.

Sorry

cedewey’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

The Drupal 6 version of Maxlength is no longer supported so I'm marking this Closed (won't fix).

I also encourage you, if you haven't already, to upgrade your site to Drupal 8/9. We are actively maintaining that version and you would enjoy all of the other features of the latest version of Drupal.