You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 line
1.2KB

  1. <?php
  2. /**
  3. * Validate all attributes in the tokens.
  4. */
  5. class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
  6. {
  7. /**
  8. * @param HTMLPurifier_Token[] $tokens
  9. * @param HTMLPurifier_Config $config
  10. * @param HTMLPurifier_Context $context
  11. * @return HTMLPurifier_Token[]
  12. */
  13. public function execute($tokens, $config, $context)
  14. {
  15. // setup validator
  16. $validator = new HTMLPurifier_AttrValidator();
  17. $token = false;
  18. $context->register('CurrentToken', $token);
  19. foreach ($tokens as $key => $token) {
  20. // only process tokens that have attributes,
  21. // namely start and empty tags
  22. if (!$token instanceof HTMLPurifier_Token_Start && !$token instanceof HTMLPurifier_Token_Empty) {
  23. continue;
  24. }
  25. // skip tokens that are armored
  26. if (!empty($token->armor['ValidateAttributes'])) {
  27. continue;
  28. }
  29. // note that we have no facilities here for removing tokens
  30. $validator->validateToken($token, $config, $context);
  31. }
  32. $context->destroy('CurrentToken');
  33. return $tokens;
  34. }
  35. }
  36. // vim: et sw=4 sts=4