-
Notifications
You must be signed in to change notification settings - Fork 14
Add a way to customize the load command to run loadHTML or pass addition... #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,31 @@ public function testScanDom() | |
$this->assertEquals($node->nodeValue, 'test'); | ||
} | ||
|
||
/** | ||
* @requires PHP 5.4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about PHP 5.3? Can there be a test for it as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5.3 does not allow any parameters to be passed to loadHtml so LIBXML_NONET can not be passed in, see http://php.net/manual/de/domdocument.loadhtml.php I'm unsure if this can be fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, we need 5.3 compatibility here for now :-\ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only option I see atm is to fall back to an xml parser in case php 5.3 and scanHtml is being used. This might yield weird results though so I'm unsure if this is the way to go. Or maybe throw an exception if its used on PHP 5.3 and tell the user to use loadXml instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ezimuel ping on this.
Can't really do, as there are parts of the codebase loading DOM nodes that are indeed used also in PHP 5.3 context. Writing an HTML parser is not attracting either, and would just be another huge source of trouble. |
||
*/ | ||
public function testScanDomHTML() | ||
{ | ||
// loadHtml accepts constants in php >= 5.4 | ||
// http://php.net/manual/de/domdocument.loadhtml.php | ||
// LIBXML_HTML_NODEFDTD and LIBXML_HTML_NOIMPLIED require libxml 2.7.8+ | ||
// http://php.net/manual/de/libxml.constants.php | ||
if (version_compare(LIBXML_DOTTED_VERSION, '2.7.8', '<')) { | ||
$this->markTestSkipped( | ||
'libxml 2.7.8+ required but found ' . LIBXML_DOTTED_VERSION | ||
); | ||
} | ||
|
||
$dom = new DOMDocument('1.0'); | ||
$html = <<<HTML | ||
<p>a simple test</p> | ||
HTML; | ||
$constants = LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED; | ||
$result = XmlSecurity::scanHtml($html, $dom, $constants); | ||
$this->assertTrue($result instanceof DOMDocument); | ||
$this->assertEquals($html, trim($result->saveHtml())); | ||
} | ||
|
||
public function testScanInvalidXml() | ||
{ | ||
$xml = <<<XML | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if those flags are not existing at all? Just a hard failure in the test suite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ATM yes, I'll add a check for libxml version and skip the test like mentioned in the phpunit docs, sec ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done