File indexing completed on 2024-12-22 05:36:20

0001 <?php
0002 
0003 /**
0004  * Validate all attributes in the tokens.
0005  */
0006 
0007 class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
0008 {
0009 
0010     /**
0011      * @param HTMLPurifier_Token[] $tokens
0012      * @param HTMLPurifier_Config $config
0013      * @param HTMLPurifier_Context $context
0014      * @return HTMLPurifier_Token[]
0015      */
0016     public function execute($tokens, $config, $context)
0017     {
0018         // setup validator
0019         $validator = new HTMLPurifier_AttrValidator();
0020 
0021         $token = false;
0022         $context->register('CurrentToken', $token);
0023 
0024         foreach ($tokens as $key => $token) {
0025 
0026             // only process tokens that have attributes,
0027             //   namely start and empty tags
0028             if (!$token instanceof HTMLPurifier_Token_Start && !$token instanceof HTMLPurifier_Token_Empty) {
0029                 continue;
0030             }
0031 
0032             // skip tokens that are armored
0033             if (!empty($token->armor['ValidateAttributes'])) {
0034                 continue;
0035             }
0036 
0037             // note that we have no facilities here for removing tokens
0038             $validator->validateToken($token, $config, $context);
0039         }
0040         $context->destroy('CurrentToken');
0041         return $tokens;
0042     }
0043 }
0044 
0045 // vim: et sw=4 sts=4