It is common practice in Drupal core to generate attributes like class=" collapsible", where the leading space is caused by not caring about whether there is a preceeding component in the attribute or not. By trim()-ing the value, we loose these spaces. This is a HTML level strictness fix, and is certainly not required, but is a small change for a nice effect.

CommentFileSizeAuthor
Drupal.trim.attributes.patch.txt562 bytesgábor hojtsy

Comments

webernet’s picture

Status: Reviewed & tested by the community » Needs review

Please do not RTBC your own patches.

forngren’s picture

Status: Needs review » Reviewed & tested by the community

Successfully tested, a step closer to perfect, strict xhtml in Drupal. I can't see why this shouldn't be RTBC.

bdragon’s picture

+1, "I can't believe I didn't think of this myself"

drumm’s picture

Status: Reviewed & tested by the community » Needs work

The root problem should be fixed, bad values shouldn't be passed in for class names.

gábor hojtsy’s picture

These are not bad values. It is a fact that it is much easier/cleaner to generate strings with: while(...) { $string .= ' something'; } or while(...) { $string .= 'something '; } (note the leading and trailing whitespace). It is IMHO not a good idea to check for the string being empty or not everytime. This leads to possible spaces at the end/beginning of a strings.

These are not bad values for HTML either, since browsers trim these spaces as the attribute value normalization rules specify. These attributes only look bad when you view the HTML and/or need to parse it yourself, and/or you are optimizing for HTML size. If all these are out of the picture, then applying this patch is a very small performance hit for no gain (fixing the 'bad' places would be a bigger peformance hit probably, but still a very small one).

Steven’s picture

The code that generates such attributes should be changed instead. For example for classes, you'd make a $classes array and implode(' ', ) it. This is the recommended way in core... if there are places where we still use strings, they should be fixed.

bdragon’s picture

Version: 5.0-rc1 » 7.x-dev
Status: Needs work » Closed (duplicate)