When using the text filter module, if the title attribute is left empty, the caption shows " width= which seems to indicate the regular expression which checks for the pretense of the title attribute is failing somehow. I changed line 108 in the image_caption_filter.module and it seemed to fix the problem. Honestly, the current code seems fine to me since + checks for 1 or more characters which I would assume is what we want. Sometimes RexEx is weird I guess. :o/

Line 108 in image_caption_filter.module

$has_title = preg_match('/title=\"(.+?)\"/i', $img_tag, $matches) > 0;

to

$has_title = preg_match('/title=\"(.*?)\"/i', $img_tag, $matches) > 0;

Comments

jrstmartin’s picture

OMG THANK YOU! I lost some hair over that one! Same problem on 6.x-2.5. This is kind of a major issue assuming not everyone is going to put a caption on every image.

joglin’s picture

Subscribe.

Try it with

$img_tag = '<img alt="" class="caption-image" height="157" src="http://localhost/d7stable/sites/default/files/styles/medium/public/images/0065.jpg" title="" width="220" />'

I suggest

$has_title = preg_match('/title="([^"]+)"/i', $img_tag, $matches) > 0;

is more fast.
Even others regex have the same bug

davidneedham’s picture

Status: Active » Needs review
StatusFileSize
new2.8 KB

I can confirm this fix works. I rolled these proposed changed into a patch for review.

davidneedham’s picture

Oops, made a mistake in the original patch. Here's a fixed version.

davidneedham’s picture

The previous patch included a lot of whitespace fixes that my code editor automatically removed. Here's a new patch that only touches the fix and not the whitespacing.