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.

42 lines
1.0KB

  1. <?php
  2. /**
  3. * Post-transform that performs validation to the name attribute; if
  4. * it is present with an equivalent id attribute, it is passed through;
  5. * otherwise validation is performed.
  6. */
  7. class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
  8. {
  9. public function __construct()
  10. {
  11. $this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
  12. }
  13. /**
  14. * @param array $attr
  15. * @param HTMLPurifier_Config $config
  16. * @param HTMLPurifier_Context $context
  17. * @return array
  18. */
  19. public function transform($attr, $config, $context)
  20. {
  21. if (!isset($attr['name'])) {
  22. return $attr;
  23. }
  24. $name = $attr['name'];
  25. if (isset($attr['id']) && $attr['id'] === $name) {
  26. return $attr;
  27. }
  28. $result = $this->idDef->validate($name, $config, $context);
  29. if ($result === false) {
  30. unset($attr['name']);
  31. } else {
  32. $attr['name'] = $result;
  33. }
  34. return $attr;
  35. }
  36. }
  37. // vim: et sw=4 sts=4