Welcome! » Log In » Create A New Profile

Altering the Strategy

Posted by bago 
Altering the Strategy
December 15, 2008 07:53AM

I see that HTMLPurifier uses the strategy pattern for the main strategy sequence and the base strategy is a composite strategy "Core" that hardcode the following strategies: RemoveForeignElements, MakeWellFormed, FixNesting, ValidateAttributes.

I have use cases where I only need to run MakeWellFormed AND ValidateAttributes and I already checked that changing the "Core" strategy fix my issue.

I looking into the code but it seems there is no way to alter the strategy because strategy is set during initialization and it is a private property.

Am I missing anything?

Is it possible to add some way to alter the strategy object without altering the core htmlpurifier code?

Re: Altering the Strategy
December 15, 2008 04:02PM

Extend HTMLPurifier and modify the constructor to pass your own strategy.

If you find any bugs running MakeWellFormed w/o RemoveForeignElements please report them; HTML Purifier's supposed to work without it, but it may not be perfect. Also this modified strategy will not be XSS safe or standards compliant, and, to boot, validate attributes will nuke some attributes that you might want to keep.

Sorry, you do not have permission to post/reply in this forum.