Page MenuHomePhabricator

Image syntax does not parse "px" in image caption correctly
Closed, ResolvedPublic

Description

Author: brianna.laugher

Description:
Hello,

When inserting an image in an article, if the image caption in an image ends in
"px", the image does not display correctly.

these display the entire image:

[[Image:Bratislava_New_Year_Fireworks.jpg|300px|this is 300px]]
[[Image:Bratislava_New_Year_Fireworks.jpg|300px|px]]

this displays at 30px instead of 300px (but it is a kind of stupid thing to
write, anyway):

[[Image:Bratislava_New_Year_Fireworks.jpg|300px|30px]]

this displays correctly:

[[Image:Bratislava_New_Year_Fireworks.jpg|300px|300px image]]

thanks!


Version: unspecified
Severity: normal
OS: Windows XP
Platform: PC

Details

Reference
bz8335

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:29 PM
bzimport set Reference to bz8335.
bzimport added a subscriber: Unknown Object (MLST).

Note that some pages contain images which are sized using a double "pxpx" suffix.
This generally occurs because of templates taking an image width in parameter,
and that
internally add the "px" suffix automatically, when the actual parameter already
contains
that suffix.
Before r18465, parsing "30pxpx" with intval() worked (because the extra "px"
suffix is actually ignored);
but in r18465, it now checks if the parameter is_numeric(), which will fail with
"30px" (after the first
suffix was parsed and removed), but will work only with "30" (after the first
suffix was parsed and
removed).

One fix in r18465 is enough: just checking if $width is set before attempting to
parse it as a image size.
The second fix added, using is_numeric(), should be tested.

Check this:
[[Image:Bratislava_New_Year_Fireworks.jpg|300pxpx|300px image]]
This should still display a 300px thumbnail, not the full image.

I've reverted part of the fix in r18483, so that the previous behavior is
restored for "300 px" and "300pxpx" cases.

It's a bit dubious, but this could use some general improvements. :)