note 94078 added to class.domnamednodemap
| From: | xafford at osu1 dot php dot net | Date: | Thu, 15 Oct 2009 10:16:04 +0000 |
| Subject: | note 94078 added to class.domnamednodemap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161756@lists.php.net to get a copy of this message | ||
I stumbled upon a problem with DOMNamedNodeMap. If you iterate over a DOMNamedNodeMap, representing
the attributes of a DOMElement with foreach and you use DOMElement::removeAttributeNode only the
first attribute will be handled.
Example (not complete):
<?php
/*
* Imagine you got a node like this:
* <a onclick="alert('evil')" href="http://someurl.example">evil</a>
* and onclick should be removed, href would not be tested.
*/
foreach ( $node->attributes as $attribute )
{
echo 'checking attribute ', $attribute->name, '<br />';
if ( ! in_array ( $attribute->name, $allowed_attributes ) )
{
$node->removeAttributeNode ( $attribute );
}
}
?>
The output would be:
checking attribute onclick
----
Server IP: 69.147.83.197
Probable Submitter: 91.45.41.246
----
Manual Page -- http://www.php.net/manual/en/class.domnamednodemap.php
Edit -- https://master.php.net/note/edit/94078
Del: integrated -- https://master.php.net/note/delete/94078/integrated
Del: useless -- https://master.php.net/note/delete/94078/useless
Del: bad code -- https://master.php.net/note/delete/94078/bad+code
Del: spam -- https://master.php.net/note/delete/94078/spam
Del: non-english -- https://master.php.net/note/delete/94078/non-english
Del: in docs -- https://master.php.net/note/delete/94078/in+docs
Del: other reasons-- https://master.php.net/note/delete/94078
Reject -- https://master.php.net/note/reject/94078
Search -- https://master.php.net/manage/user-notes.php