Skip to content

Commit 6f6fedc

Browse files
committed
Handle strict error properly in adoptNode failure, and add a test
1 parent 6fc8ab2 commit 6f6fedc

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

ext/dom/document.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ PHP_METHOD(DOMDocument, adoptNode)
10641064
|| nodep->type == XML_ENTITY_NODE
10651065
|| nodep->type == XML_NOTATION_NODE)) {
10661066
php_dom_throw_error(NOT_SUPPORTED_ERR, dom_get_strict_error(dom_object_nodep->document));
1067-
RETURN_THROWS();
1067+
RETURN_FALSE;
10681068
}
10691069

10701070
xmlDocPtr new_document;

ext/dom/tests/DOMDocument_adoptNode.phpt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,24 @@ $adopted = $doc1->adoptNode($doc1->firstChild->firstChild);
4343
var_dump($adopted->textContent);
4444
var_dump($doc1->saveXML());
4545

46-
echo "-- Adopt a document --\n";
46+
echo "-- Adopt a document (strict error on) --\n";
4747

4848
try {
4949
$doc1->adoptNode($doc1);
5050
} catch (\DOMException $e) {
5151
echo $e->getMessage(), "\n";
5252
}
5353

54+
echo "-- Adopt a document (strict error off) --\n";
55+
56+
$doc1->strictErrorChecking = false;
57+
try {
58+
$doc1->adoptNode($doc1);
59+
} catch (\DOMException $e) {
60+
echo $e->getMessage(), "\n";
61+
}
62+
$doc1->strictErrorChecking = true;
63+
5464
echo "-- Adopt an attribute --\n";
5565

5666
$doc3 = new DOMDocument();
@@ -102,7 +112,7 @@ unset($doc1);
102112
var_dump($child->nodeName);
103113

104114
?>
105-
--EXPECT--
115+
--EXPECTF--
106116
-- Owner document check before adopting --
107117
bool(true)
108118
bool(false)
@@ -127,8 +137,11 @@ string(5) "world"
127137
string(27) "<?xml version="1.0"?>
128138
<p/>
129139
"
130-
-- Adopt a document --
140+
-- Adopt a document (strict error on) --
131141
Not Supported Error
142+
-- Adopt a document (strict error off) --
143+
144+
Warning: DOMDocument::adoptNode(): Not Supported Error in %s on line %d
132145
-- Adopt an attribute --
133146
bool(true)
134147
bool(true)

0 commit comments

Comments
 (0)