Last modified: 2013-03-22 00:52:24 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T37002, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 35002 - Sanitizer:removeHTMLtags fails for <img src=> tag when enclosed in <a> link
Sanitizer:removeHTMLtags fails for <img src=> tag when enclosed in <a> link
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.20.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on: 35013
Blocks: 34763
  Show dependency treegraph
 
Reported: 2012-03-06 08:33 UTC by T. Gries
Modified: 2013-03-22 00:52 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description T. Gries 2012-03-06 08:33:25 UTC
Scenario:

if you want to strip all insane tags but allow "a" and "img" tags, you would use this

$string = Sanitizer::removeHTMLtags( $string, null, array(), array( "a", "img" ) );

This leaves single "a" and "img" tags, but I noticed that the Sanitizer function does not work correctly for such string :

<a href='http://link-url'><img src='http://image-url'></a>

Because this a widely used construct I suggest to fix the removeHTMLtgas have it working for this case, too.

I also noticed that the function fails in the constructed case where the image tag is intentionally incorrectly written as a closed tag <img src='http://image-url' />
Comment 1 Bawolff (Brian Wolff) 2012-03-06 15:20:08 UTC
(In reply to comment #0)
> Scenario:
> 
> if you want to strip all insane tags but allow "a" and "img" tags, you would
> use this
> 
> $string = Sanitizer::removeHTMLtags( $string, null, array(), array( "a", "img"
> ) );
> 
> This leaves single "a" and "img" tags, but I noticed that the Sanitizer
> function does not work correctly for such string :
> 
> <a href='http://link-url'><img src='http://image-url'></a>
> 
> Because this a widely used construct I suggest to fix the removeHTMLtgas have
> it working for this case, too.

Works fine if you have $wgAllowImageTag = true; set in your LocalSettings.php. I suppose the fourth parameter of that function is not meant for self-closing tags.

> I also noticed that the function fails in the constructed case where the image
> tag is intentionally incorrectly written as a closed tag <img
> src='http://image-url' />

Valid in XHTML! (although we don't use xhtml any more...)
Comment 2 T. Gries 2012-03-06 22:13:06 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > Scenario:
> > 
> > if you want to strip all insane tags but allow "a" and "img" tags, you would
> > use this

> > I also noticed that the function fails in the constructed case where the image
> > tag is intentionally incorrectly written as a closed tag <img
> > src='http://image-url' />
> 
> Valid in XHTML! (although we don't use xhtml any more...)

$wgAllowImageTag = true; // I already had this, but overlooked to uncomment it!
// thanks for pointing me to that self-made problem.

My RSS HTML problems are now ->almost solved, but the <img ..../> remains. I will file a separate bug for it
Comment 3 T. Gries 2013-03-22 00:52:24 UTC
Regarding the last sentence of the description of this bug:

"I also noticed that the function fails in the constructed case where the image
tag is intentionally incorrectly written as a closed tag <img
src='http://image-url' />"

this is an ongoing problem, and has now been separately filed as bug 46443 .

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links