Opened 20 years ago
Last modified 20 years ago
#5 new defect
Valid XHTML 1.1
| Reported by: | lonemadmax | Owned by: | mdawaffe |
|---|---|---|---|
| Priority: | normal | Component: | allow-images |
| Keywords: | valid markup XHTML | Cc: |
Description
As is, this plugin may generate img tags without the closing mark (as <img ... > instead of <img ... />), without the required alt attribute and even without any attribute. The default template presents itself as XHTML 1.1, for which those cases are invalid. This patch solves it (or it worked for me).
If this is considered for merging, please double check the code, as I don't know regexes, php or bbPress' internals.
There's still the problem of the last attribute being deleted if there's no space before de closing mark (in <img src="pic.png" alt="text"> the alt attribute won't be seen), but I guess that is bbPress' handling of markup and not this plugin.

As is, this plugin may generate img tags without the closing mark (as <img ... > instead of <img ... />), without the required alt attribute and even without any attribute. The default template presents itself as XHTML 1.1, for which those cases are invalid. This patch solves it (or it worked for me).
If this is considered for merging, please double check the code, as I don't know regexes, php or bbPress' internals.
There's still the problem of the last attribute being deleted if there's no space before de closing mark (in <img src="pic.png" alt="text"> the alt attribute won't be seen), but I guess that is bbPress' handling of markup and not this plugin.
So I'm stupid or something, and every attempt to attach a file ends in Error 13. I'm copying it here as text, and hoping it doesn't break.
--- allow-images.php.orig Mon Jan 22 02:02:10 2007 +++ allow-images.php Tue Jan 23 20:03:45 2007 @@ -32,15 +32,23 @@ } function allow_images( $text ) { - if ( preg_match_all('/<img(.+?)src=("|\')(.+?)\\2(.+?)>/i', $text, $matches, PREG_SET_ORDER ) ) + if ( preg_match_all('/<img(\s.*)?>/i', $text, $matches, PREG_SET_ORDER ) ) foreach( $matches as $match ) if ( - preg_match('/src=/i', $match[4]) // multiple src = someone's trying to cheat - || - !in_array(substr($match[3], -4), array('.png', '.jpg', '.gif')) // only match .jpg, .gif, .png + preg_match('/.*(\ssrc=("|\')(.+?)\\2).+?/i', $match[0], $lfsrc ) && - '.jpeg' != substr($match[3], -5) // and .jpeg - ) + ( in_array(substr($lfsrc[3], -4), array('.png', '.jpg', '.gif')) + || '.jpeg' == substr($lfsrc[3], -5)) + ) { + // good src + $title = ""; + if ( preg_match('/.*(\stitle=("|\')(.+?)\\2).+?/i', $match[0], $lftitle ) ) + $title = $lftitle[1]; + if ( preg_match('/.*(\salt=("|\')(.+?)\\2).+?/i', $match[0], $lfalt ) ) + $text = str_replace($match[0], '<img' . $lfalt[1] . $title . $lfsrc[1] . ' />', $text); + else + $text = str_replace($match[0], '<img alt=""' . $title . $lfsrc[1] . ' />', $text); + } else $text = str_replace($match[0], '', $text); return $text; }