@@ -865,6 +865,39 @@ static xmlNodePtr _php_dom_insert_fragment(xmlNodePtr nodep, xmlNodePtr prevsib,
865
865
}
866
866
/* }}} */
867
867
868
+ static bool dom_node_check_legacy_insertion_validity(xmlNodePtr parentp, xmlNodePtr child, bool stricterror)
869
+ {
870
+ if (dom_node_is_read_only(parentp) == SUCCESS ||
871
+ (child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
872
+ php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
873
+ return false;
874
+ }
875
+
876
+ if (dom_hierarchy(parentp, child) == FAILURE) {
877
+ php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
878
+ return false;
879
+ }
880
+
881
+ if (child->doc != parentp->doc && child->doc != NULL) {
882
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, stricterror);
883
+ return false;
884
+ }
885
+
886
+ if (child->type == XML_DOCUMENT_FRAG_NODE && child->children == NULL) {
887
+ /* TODO Drop Warning? */
888
+ php_error_docref(NULL, E_WARNING, "Document Fragment is empty");
889
+ return false;
890
+ }
891
+
892
+ /* In old DOM only text nodes and entity nodes can be added as children to attributes. */
893
+ if (parentp->type == XML_ATTRIBUTE_NODE && child->type != XML_TEXT_NODE && child->type != XML_ENTITY_REF_NODE) {
894
+ php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
895
+ return false;
896
+ }
897
+
898
+ return true;
899
+ }
900
+
868
901
/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-952280727
869
902
Since:
870
903
*/
@@ -892,25 +925,7 @@ PHP_METHOD(DOMNode, insertBefore)
892
925
893
926
stricterror = dom_get_strict_error(intern->document);
894
927
895
- if (dom_node_is_read_only(parentp) == SUCCESS ||
896
- (child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
897
- php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
898
- RETURN_FALSE;
899
- }
900
-
901
- if (dom_hierarchy(parentp, child) == FAILURE) {
902
- php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
903
- RETURN_FALSE;
904
- }
905
-
906
- if (child->doc != parentp->doc && child->doc != NULL) {
907
- php_dom_throw_error(WRONG_DOCUMENT_ERR, stricterror);
908
- RETURN_FALSE;
909
- }
910
-
911
- if (child->type == XML_DOCUMENT_FRAG_NODE && child->children == NULL) {
912
- /* TODO Drop Warning? */
913
- php_error_docref(NULL, E_WARNING, "Document Fragment is empty");
928
+ if (!dom_node_check_legacy_insertion_validity(parentp, child, stricterror)) {
914
929
RETURN_FALSE;
915
930
}
916
931
@@ -1196,25 +1211,7 @@ PHP_METHOD(DOMNode, appendChild)
1196
1211
1197
1212
stricterror = dom_get_strict_error(intern->document);
1198
1213
1199
- if (dom_node_is_read_only(nodep) == SUCCESS ||
1200
- (child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
1201
- php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
1202
- RETURN_FALSE;
1203
- }
1204
-
1205
- if (dom_hierarchy(nodep, child) == FAILURE) {
1206
- php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
1207
- RETURN_FALSE;
1208
- }
1209
-
1210
- if (!(child->doc == NULL || child->doc == nodep->doc)) {
1211
- php_dom_throw_error(WRONG_DOCUMENT_ERR, stricterror);
1212
- RETURN_FALSE;
1213
- }
1214
-
1215
- if (child->type == XML_DOCUMENT_FRAG_NODE && child->children == NULL) {
1216
- /* TODO Drop Warning? */
1217
- php_error_docref(NULL, E_WARNING, "Document Fragment is empty");
1214
+ if (!dom_node_check_legacy_insertion_validity(nodep, child, stricterror)) {
1218
1215
RETURN_FALSE;
1219
1216
}
1220
1217
0 commit comments