This code:

<!--<b><a href="https://services.myngp.com/ngponlineservices/contribution.aspx?X=u79dmcfUhnWbdcpV1NfXqQ%3d%3d">Contribute</a></b>
Help Congressman Lewis win reelection.-->

Produces this output:

Contribute
Help Congressman Lewis win reelection.-->

CommentFileSizeAuthor
#7 filter_comments_head.patch640 bytesstevenpatz
#2 filter.module_24.patch736 bytesseanr

Comments

seanr’s picture

Title: Multiline comments containing HTML are broken (only leading tag is stripped) » Comments containing HTML are broken (only leading tag is stripped)

Doesn't need to be multiline either, evidently:

<!--<br>test-->

seanr’s picture

StatusFileSize
new736 bytes

This patch completely removes the comment and it's content from the output before any other filters are applied (except the NULL replacement).

Steven’s picture

Unfortunately, the state of comments in HTML is vague:

  • The XML specs (and thus XHTML 1.0 by extension) state that a comment must begin in <!-- and end in -->.
  • The HTML4 specs say that a comment begins with <!-- and end in --, optional whitespace and >.
  • The SGML specs (and HTML4 by extension?) says that a comment begins with <!, ends with > and contains an arbitrary amount of segments which each begin and end in --.

I know that correct application of the SGML rule is one of the checks in the ACID2 browser compliancy test. So it would seem that the HTML specs only serve as simple examples of the SGML comment rules. The phrasing in the HTML specs is a bit vague anyway.

Part of ACID2:

<div class="parser"><!-- ->ERROR<!- --></div></div> <!-- two dashes is what delimits a comment, so the text "->ERROR<!-" earlier on this line is actually part of a comment -->

Which one do we follow? Given that unremoved comments are still subject to the proper filtering later, it does not matter that much. What's important is that we catch the most common usage (which would be the HTML form, IMO).

Ungreedy matching should be avoided though.

For the 'stupid' HTML syntax, we should use /<!--(-[^-]|[^-])*--\s*>/s.
If we want to follow true SGML syntax, it needs to be /<!(--(-[^-]|[^-])*)--\s*)*>/s.

The code comment is misleading though, about "potentially nasty contents". HTML comments do not pose a security risk, for their 'potentially nasty' content is removed with or without this patch anyway. It is merely ugly and undesirable to print out any part of comments on screen.

magico’s picture

Version: 4.7.2 » x.y.z

Pushing this up!

@Steven: I think we should follow XHTML specification.

flevour’s picture

This patch needs only opinionated opinions by someone of the core team.
I'd go for the XHTML one since it's the only one that I ever heard about.
I guess it's possible to setup an ugly regex that handles all three standards.
Cheers,
flevour

stevenpatz’s picture

Version: x.y.z » 6.x-dev
Status: Active » Needs review
stevenpatz’s picture

StatusFileSize
new640 bytes

rerolled for HEAD

Steven’s picture

Status: Needs review » Needs work

The ungreedy matching in the patch's regexp will cause a lot of unnecessary backtracking.

dpearcefl’s picture

Is this an issue in the current 6.X Drupal?

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.