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
Comment #1
jonbob commented+1 for this change, but the version should be CVS.
Comment #2
bdragon commentedYou know, this is still a valid feature request, I believe..
Comment #3
sunComment #4
HenryLTV commentedThis 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
Comment #5
HenryLTV commentedNevermind. 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.
Comment #6
Leeland commentedCan you post the patch here so we can use it. That is exactly what I want to do.
Comment #7
HenryLTV commentedHi 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.
Comment #8
jeremy commentedI 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.
Comment #9
jeremy commentedWhoops, wrong version of my patch -- re-attaching. (Still doesn't work, though. ;)
Comment #10
Georgique commentedBased on @Jeremy patch I've created patch for Drupal 7.x.
Comment #12
wim leersThis is an exotic need. Let's not fill core with <1% needs.
Comment #13
sunThis is a fairly reasonable change request, which would certainly help to make more sense of the combination of both filters.
Comment #14
wim leersI disagree, but okay.
Comment #15
Georgique commentedMy patch should be good but it has to be properly formatted, will do it in 1-2 weeks.
Comment #16
Georgique commentedHere is the patch in proper format
Comment #17
Georgique commentedComment #19
Georgique commented