While working on #200185: truncate_utf8() is used as a substring function I came across this piece of code (in _comment_form_submit()
):
$comment_values['subject'] = trim(truncate_utf8(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['comment_format']))), 29, TRUE));
And while nothing is functionally wrong with that, it just seems to me that it would be smarter to trim()
before truncating, as 1) truncate_utf8()
doesn't (and shouldn't) append or prepend any whitespace to the string given, and 2) if the string sent to truncate_utf8()
is already trim()
'ed, there is just a bit slighter chance of truncate_utf8()
actually truncating the string - and even if it does, it won't use the whitespace that is being removed anyway as grounds for its truncating.
This applies to 7.x, 6.x, and 5.x. And patches provided for each. :)
Comment | File | Size | Author |
---|---|---|---|
trim_inside_truncate-0-d5.patch | 1.01 KB | Freso | |
trim_inside_truncate-0-d6.patch | 1.02 KB | Freso | |
trim_inside_truncate-0-d7.patch | 1.03 KB | Freso | |
Comments
Comment #2
Freso CreditAttribution: Freso commented... That is hardly the fault of this patch.
Comment #4
Freso CreditAttribution: Freso commentedApparently test node #16 has gone bonkers, so still keeping my claim that this is not the fault of this patch. :)
Comment #5
catchComment #6
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks!
Comment #7
Gábor HojtsyThanks, committed to Drupal 6 too. Moving to 5.
Comment #8
drummCommitted to 5.x.