Currently, if the "Filter HTML tags" option is set to "Strip tags," then only the tags not listed under "Allowed HTML tags" will be stripped. However, if the "Filter HTML tags" option is set to "Escape tags," then all HTML is escaped.

I would like to suggest that "Allowed HTML tags" be set as exceptions to this. That way, if I want to allow only the <b> and <i> tags, they will work, but the <font> tag will still be escaped.

The "HTML style attributes (Allowed/Removed)" setting should also affect the output for allowed tags. If set to "Removed," then the allowed tags should have any style attributes stripped.

Comments

jonbob’s picture

+1 for this change, but the version should be CVS.

bdragon’s picture

Version: » 7.x-dev

You know, this is still a valid feature request, I believe..

sun’s picture

Version: 7.x-dev » 8.x-dev
HenryLTV’s picture

This seems like a very logical feature to have. After all, if we have a white-list of tags not to strip, it's not that far of a stretch to imagine that we wouldn't want to escape them either =)

Considering @sun's change from Drupal 7.x to 8.x, does anyone have suggestions on a viable workaround to implement this while we wait for Drupal 8?

Thanks!
Henry

HenryLTV’s picture

Nevermind. We were able to patch the filter module to add the option & functionality to "Escape disallowed tags" which basically combines the logic from the included "Strip disallowed tags" and "Escape all tags" options.

Was very quick and easy, took maybe 30 minutes to add this much needed functionality. Hopefully this feature request makes it into Drupal core someday. Works very well combined with CodeFilter module to allow much safer, yet permissive Forum postings than "Escape All" or "Strip disallowed tags" can provide individually.

Leeland’s picture

Can you post the patch here so we can use it. That is exactly what I want to do.

HenryLTV’s picture

Hi Leeland,

I'll try to post our patch, but we have a few upcoming releases next week so I can't promise a patch until after the releases.

In the meantime here's a quick rundown of what we did:
* Modified filter.module
* In filter_html_settings() function: added a new option to the list of filters called 'Escape Disallowed Tags'
* In filter_html() function: added new conditional (copy/pasted one of the others) that captures the new option created, except called a custom function escape_xss().
* Defined custom function escape_xss() that handles your escape/filter logic (customized by merging existing core "escape all" logic and filter_xss logic) : calls custom function escape_xss_split()
* Defined custom function escape_xss_split() based from filter_xss_split

In summary, like i mentioned in my earlier post, we just took the exisiting core logic for escaping and filtering (stripping disallowed tags), merged them into our custom functions, and created a new filter option that calls these custom functions.

Hope this helps, and if we have time we'll try to post a patch for you.

jeremy’s picture

Status: Active » Needs work
StatusFileSize
new4.08 KB

I added something like the attached to a 6.x site, but it doesn't appear to work as-is on 7.x+. Perhaps it's enough to get someone else started. Adding a parameter to filter_xss() and _filter_xss_split() feels a bit dirty.

jeremy’s picture

StatusFileSize
new4.12 KB

Whoops, wrong version of my patch -- re-attaching. (Still doesn't work, though. ;)

Georgique’s picture

Status: Needs work » Needs review
StatusFileSize
new4.2 KB

Based on @Jeremy patch I've created patch for Drupal 7.x.

Status: Needs review » Needs work

The last submitted patch, filter_display_unallowed_tags.patch, failed testing.

wim leers’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

This is an exotic need. Let's not fill core with <1% needs.

sun’s picture

Title: Exceptions to "Escape HTML Tags" » Make "Escape HTML" filter skip the allowed tags of HTML filter
Category: Feature request » Task
Status: Closed (won't fix) » Needs work

This is a fairly reasonable change request, which would certainly help to make more sense of the combination of both filters.

wim leers’s picture

I disagree, but okay.

Georgique’s picture

My patch should be good but it has to be properly formatted, will do it in 1-2 weeks.

Georgique’s picture

Here is the patch in proper format

Georgique’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 16: drupal-display_unallowed_tags-10200-16.patch, failed testing.

Georgique’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 16: drupal-display_unallowed_tags-10200-16.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.