Testing Drupal 7: when the siggie is too long, I get the following ugly message:

PDOException: UPDATE {users} SET name=:db_update_placeholder_0, mail=:db_update_placeholder_1, signature=:db_update_placeholder_2, status=:db_update_placeholder_3, timezone=:db_update_placeholder_4, picture=:db_update_placeholder_5, data=:db_update_placeholder_6 WHERE (uid = :db_condition_placeholder_8) - Array ( [:db_update_placeholder_0] => Dandy [:db_update_placeholder_1] => (emailremoved) [:db_update_placeholder_2] => She was not quite what you would call refined. She was not quite what you would call unrefined. She was the kind of person that keeps a parrot. Mark Twain - Following the Equator <a href="http://africangreyparrot.info">Visit African Grey Parrot Info</a> [:db_update_placeholder_3] => 1 [:db_update_placeholder_4] => America/Dawson_Creek [:db_update_placeholder_5] => 3 [:db_update_placeholder_6] => a:2:{s:5:"block";a:0:{}s:7:"contact";i:1;} [:db_condition_placeholder_8] => 4 ) SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'signature' at row 1 in drupal_write_record() (line 3987 of /home/sophia/public_html/d7/includes/common.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

deekayen’s picture

Status: Active » Needs review
FileSize
1.2 KB

Patch adds validation to the user submit form to make sure the length of the signature doesn't exceed the size of the signature column in the schema definition (currently 255).

deekayen’s picture

Update adds some new tests.

Dries’s picture

Any reason you created that function user_validate_signature()? It is only used once -- I think it could be rolled into the main validate function.

deekayen’s picture

Yes, it could be, but I thought it'd be nice for it to be available to be re-usable. Never know what kinds of crazy needs will pop up in contrib...

Status: Needs review » Needs work

The last submitted patch failed testing.

deekayen’s picture

Status: Needs work » Needs review
FileSize
1.05 KB

This version rolls the validation into the main user_user_validate() function.

deekayen’s picture

Status: Needs review » Needs work
deekayen’s picture

Status: Needs work » Needs review
FileSize
1.06 KB

same as #6 with a corrected signature variable

catch’s picture

The two inline comments should be rolled into one above the if statement - we don't usually put comments inline with brackets like that

What about making the signature field a text field and adding maxlength to it instead?

deekayen’s picture

Comments adjusted.

I think making it a text field would break more than an insignificant number of signatures that have line breaks. -1

Dries’s picture

Status: Needs review » Fixed

I committed this to CVS HEAD. Thanks deekayen and catch.

We can follow up with a new patch if we want to consider changing it to a textfield. I don't think it would be better either.

Dries’s picture

Status: Fixed » Needs work

Actually, I'm going to set this to 'code needs work' because it would be great to have a test for this.

catch’s picture

Title: Ugly message when signature is too long » (Tests for) Ugly message when signature is too long

textfield wasn't a good idea, forgot about line breaks. Maybe I just don't like signatures...

Damien Tournoud’s picture

Two questions about that patch:

- why don't we change the users.signature column type to 'text'?
- why don't we make textarea accept #maxlength too (it could be useful elsewhere), instead of adding cruft into the validation handler of the form itself?

deekayen’s picture

I like where Damien's thinking is wandering to. I don't think an unrestricted text field is good because people will abuse it with pages of signature URLs, job titles, and spam. A new #maxlength would just substr() or would it drupal_set_error? Then I assume that will eventually grow into adding a Javascripty limit assist?

Tor Arne Thune’s picture

Version: 7.x-dev » 8.x-dev

Can't find a test for this in Drupal 7.0 user.test, so I guess the issue is still valid.

catch’s picture

Category: bug » task
Issue tags: +Needs tests

tagging.

jhedstrom’s picture

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

Signature has been moved to contrib.