Skip to content

Commit fc9b3b9

Browse files
committed
Rename template should throw
1 parent 15fa7c6 commit fc9b3b9

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

ext/dom/element.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "zend_enum.h"
2525
#include "php_dom.h"
2626
#include "namespace_compat.h"
27-
#include "private_data.h"
2827
#include "internal_helpers.h"
2928
#include "dom_properties.h"
3029
#include "token_list.h"
@@ -2034,7 +2033,12 @@ PHP_METHOD(Dom_Element, rename)
20342033

20352034
/* If we currently have a template but the new element type won't be a template, then throw away the templated content. */
20362035
if (is_currently_html_ns && xmlStrEqual(nodep->name, BAD_CAST "template") && !xmlStrEqual(localname, BAD_CAST "template")) {
2037-
php_dom_remove_templated_content(php_dom_get_private_data(intern), nodep);
2036+
php_dom_throw_error_with_message(
2037+
INVALID_MODIFICATION_ERR,
2038+
"It is not possible to rename the template element because it hosts a document fragment",
2039+
/* strict */ true
2040+
);
2041+
goto cleanup;
20382042
}
20392043
}
20402044

ext/dom/tests/modern/common/template_rename.phpt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ $dom = Dom\HTMLDocument::createFromString($html);
1717
$template = $dom->body->firstElementChild;
1818
var_dump($template->innerHTML);
1919

20-
$template->rename($template->namespaceURI, 'screwthis');
21-
var_dump($template->innerHTML);
22-
$template->rename($template->namespaceURI, 'template');
20+
try {
21+
$template->rename($template->namespaceURI, 'screwthis');
22+
} catch (DOMException $e) {
23+
echo $e->getMessage(), "\n";
24+
}
25+
26+
// These shouldn't be changed!
27+
var_dump($template->nodeName);
2328
var_dump($template->innerHTML);
2429

2530
?>
2631
--EXPECT--
2732
string(16) "a<div>foo</div>b"
28-
string(0) ""
29-
string(0) ""
33+
It is not possible to rename the template element because it hosts a document fragment
34+
string(8) "TEMPLATE"
35+
string(16) "a<div>foo</div>b"

0 commit comments

Comments
 (0)