Skip to content

Avoid libxml2's xmlNodeSetContent #19189

@nwellnhof

Description

@nwellnhof

Description

xmlNodeSetContent decodes character and entity references which is typically not what users expect. This can be worked around by first calling xmlNodeSetContent with a NULL pointer to clear the node and then using xmlNodeAddContent which adds the string verbatim.

Here's an example:

<?php
$doc = new DOMDocument();
$doc->loadXML("<!DOCTYPE doc [ <!ENTITY e 'ent'> ]><doc/>");
$root = $doc->documentElement;
$root->nodeValue = "&lt; &e; &gt;";
echo($root->nodeValue); # prints "< ent >"

PHP Version

All versions

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions