Rename newline normalization directive to something better.
[htmlpurifier.git] / library / HTMLPurifier / AttrTransform / NameSync.php
bloba95638c140e724774ce5217576d33f097dd92787
1 <?php
3 /**
4 * Post-transform that performs validation to the name attribute; if
5 * it is present with an equivalent id attribute, it is passed through;
6 * otherwise validation is performed.
7 */
8 class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
11 public function __construct() {
12 $this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
15 public function transform($attr, $config, $context) {
16 if (!isset($attr['name'])) return $attr;
17 $name = $attr['name'];
18 if (isset($attr['id']) && $attr['id'] === $name) return $attr;
19 $result = $this->idDef->validate($name, $config, $context);
20 if ($result === false) unset($attr['name']);
21 else $attr['name'] = $result;
22 return $attr;
27 // vim: et sw=4 sts=4