Skip to content
Permalink
Browse files Browse the repository at this point in the history
Type safety in simplexml import routines
Reviewed By: Orvid

Differential Revision: D3447275

fbshipit-source-id: d859c97f9d85c520b0e371cef6dcb19bb2ef7dbf
  • Loading branch information
mxw authored and Hhvm Bot committed Jul 1, 2016
1 parent 295784f commit 8e7266f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions hphp/runtime/ext/simplexml/ext_simplexml.cpp
Expand Up @@ -374,7 +374,7 @@ static xmlNodePtr php_sxe_get_first_node(SimpleXMLElement* sxe,
}

xmlNodePtr SimpleXMLElement_exportNode(const Object& sxe) {
assert(sxe->instanceof(SimpleXMLElement_classof()));
if (!sxe->instanceof(SimpleXMLElement_classof())) return nullptr;
auto data = Native::data<SimpleXMLElement>(sxe.get());
return php_sxe_get_first_node(data, data->nodep());
}
Expand Down Expand Up @@ -1166,9 +1166,15 @@ static const Class* class_from_name(const String& class_name,
return cls;
}

const StaticString s_DOMNode("DOMNode");

static Variant HHVM_FUNCTION(simplexml_import_dom,
const Object& node,
const String& class_name /* = "SimpleXMLElement" */) {
const Object& node,
const String& class_name) {
if (!node->instanceof(s_DOMNode)) {
raise_warning("Invalid Nodetype to import");
return init_null();
}
auto domnode = Native::data<DOMNode>(node);
xmlNodePtr nodep = domnode->nodep();

Expand Down
5 changes: 5 additions & 0 deletions hphp/test/slow/ext_domdocument/simplexml_null.php
@@ -0,0 +1,5 @@
<?php

$date = date_create_immutable();
var_dump(dom_import_simplexml($date));
var_dump(simplexml_import_dom($date));
5 changes: 5 additions & 0 deletions hphp/test/slow/ext_domdocument/simplexml_null.php.expectf
@@ -0,0 +1,5 @@
Warning: Invalid Nodetype to import in %s/test/slow/ext_domdocument/simplexml_null.php on line 4
NULL

Warning: Invalid Nodetype to import in %s/test/slow/ext_domdocument/simplexml_null.php on line 5
NULL

0 comments on commit 8e7266f

Please sign in to comment.