If you go to admin/config/regional/date-time/formats/add and add a date format with more than 100 characters, you get a nice big red error:

PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'format' at row 1

The form needs to do some validation to prevent people from entering a format longer than what is allowed in the database.

Also, I think we might really consider a schema change to pump up the size of that database column; 100 seems somewhat arbitrary. (I hit the limit because I was trying to inject some HTML in there so part of the date format could be styled differently from other parts, and when you do that, the characters count up fast.)

CommentFileSizeAuthor
#5 date_format_maxlength.patch870 bytesmcarbone
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

I think this qualifies as a "major" bug, although maybe not quite critical. Blank screens with big red error messages are bad.

marcingy’s picture

Priority: Normal » Major

Changing to major as per tag.

MustangGB’s picture

Tag update

dawehner’s picture

I guess 255 would be long enough for many people?

mcarbone’s picture

Status: Active » Needs review
FileSize
870 bytes

If anything, 100 characters is too long for the date format string -- there are hardly even 30 qualified characters provided by PHP (http://php.net/manual/en/function.date.php) and I'm fairly certain I've never seen a date format string longer than 10 characters. If someone can provide a real world example as to a 100+ character date format string, then I might be persuadable -- but in general it's not good practice in the service of performance to make database fields bigger for no good reason. (The reason stated in the original issue was the desire to use HTML, which isn't the proper use of the date format string.)

All that's really needed here is a FAPI maxlength attribute.

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

@mcarbone, well, not really - in addition to the characters that get interpreted, PHP deliberately lets you put arbitrary characters in there so you can construct it as a sentence, etc. And 100 is extremely arbitrary when it comes to database column sizes; the performance effect of making it bigger would really be negligible.

However, the patch is good and solves the main part of the bug, so I'm marking it RTBC.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.