Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Or, in general, Image Resize Filter breaks any attributes that have dashes in them.
To fix this, we have to update a regular expression:
preg_match_all('/([a-z]+)[ ]*=[ ]*"([^"]*)"/i', $img_tag, $attribute_matches);
to:
preg_match_all('/([a-z\-]+)[ ]*=[ ]*"([^"]*)"/i', $img_tag, $attribute_matches);
Patch attached.
Comment | File | Size | Author |
---|---|---|---|
#7 | 1708366-7.patch | 741 bytes | Wim Leers |
image_resize_filter-data_attributes.patch | 742 bytes | Wim Leers | |
Comments
Comment #1
quicksketchThanks Wim! Maybe we should allow numbers in there too? Data attributes can contain any alphanumeric character I believe.
Comment #2
Wim LeersI just looked it up, and the spec actually says no such thing:
So AFAICT, the patch above covers all use cases :) We could make the patch more strict, not allowing dashes everywhere, but only when an attribute begins with
data-
. But I personally think that's not really necessary.Comment #3
Wim LeersBased on #2 and the simplicity of the patch, tentatively setting to RTBC.
Comment #4
jcisio CreditAttribution: jcisio commentedThat regex does not match "data-n9".
Comment #5
Wim Leers#4: are you sure that numeric characters are allowed?
Comment #6
jcisio CreditAttribution: jcisio commentedYes, if your quote #2 is correct.
After data-, any character that is XML-compatible and not A-Z is allowed. That means "data-n9" or even "data-n ͦ9" (well, we don't really need to support this case, I think) are both allowed.
Comment #7
Wim Leers#6: Hm, fair enough.
In that case, we can just use
[\w\-]+
instead of[a-z\-]+
(original:[a-z]+
).Rerolled.
Comment #8
phoehne CreditAttribution: phoehne commentedStumbled across the same problem,
patch works perfect.
Thanks Peter
Comment #9
Wim LeersSetting to RTBC as per #8.
Comment #10
Wim LeersBump. quicksketch?
Comment #11
jcisio CreditAttribution: jcisio commentedI've just read #6 again, and it says A-Z are not allowed. I let you to decide change the issue to NW or leave it as RTBC, as we don't really have to follow specs.
Comment #13
ram4nd CreditAttribution: ram4nd as a volunteer commentedComment #14
Wim LeersYay, thanks!