@@ -240,8 +240,8 @@ static void dom_fragment_assign_parent_node(xmlNodePtr parentNode, xmlNodePtr fr
240
240
241
241
static zend_result dom_sanity_check_node_list_for_insertion (php_libxml_ref_obj * document , xmlNodePtr parentNode , zval * nodes , int nodesc )
242
242
{
243
- if (document == NULL ) {
244
- php_dom_throw_error ( HIERARCHY_REQUEST_ERR , 1 );
243
+ if (UNEXPECTED ( parentNode == NULL ) ) {
244
+ /* No error required, this must be a no-op per spec */
245
245
return FAILURE ;
246
246
}
247
247
@@ -391,10 +391,9 @@ void dom_parent_node_after(dom_object *context, zval *nodes, uint32_t nodesc)
391
391
392
392
/* Spec step 1 */
393
393
parentNode = prevsib -> parent ;
394
- /* Spec step 2 */
395
- if (!parentNode ) {
396
- int stricterror = dom_get_strict_error (context -> document );
397
- php_dom_throw_error (HIERARCHY_REQUEST_ERR , stricterror );
394
+
395
+ /* Sanity check for fragment, includes spec step 2 */
396
+ if (UNEXPECTED (dom_sanity_check_node_list_for_insertion (context -> document , parentNode , nodes , nodesc ) != SUCCESS )) {
398
397
return ;
399
398
}
400
399
@@ -409,10 +408,6 @@ void dom_parent_node_after(dom_object *context, zval *nodes, uint32_t nodesc)
409
408
410
409
doc = prevsib -> doc ;
411
410
412
- if (UNEXPECTED (dom_sanity_check_node_list_for_insertion (context -> document , parentNode , nodes , nodesc ) != SUCCESS )) {
413
- return ;
414
- }
415
-
416
411
php_libxml_invalidate_node_list_cache_from_doc (doc );
417
412
418
413
/* Spec step 4: convert nodes into fragment */
@@ -448,10 +443,9 @@ void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)
448
443
449
444
/* Spec step 1 */
450
445
parentNode = nextsib -> parent ;
451
- /* Spec step 2 */
452
- if (!parentNode ) {
453
- int stricterror = dom_get_strict_error (context -> document );
454
- php_dom_throw_error (HIERARCHY_REQUEST_ERR , stricterror );
446
+
447
+ /* Sanity check for fragment, includes spec step 2 */
448
+ if (UNEXPECTED (dom_sanity_check_node_list_for_insertion (context -> document , parentNode , nodes , nodesc ) != SUCCESS )) {
455
449
return ;
456
450
}
457
451
@@ -466,10 +460,6 @@ void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)
466
460
467
461
doc = nextsib -> doc ;
468
462
469
- if (UNEXPECTED (dom_sanity_check_node_list_for_insertion (context -> document , parentNode , nodes , nodesc ) != SUCCESS )) {
470
- return ;
471
- }
472
-
473
463
php_libxml_invalidate_node_list_cache_from_doc (doc );
474
464
475
465
/* Spec step 4: convert nodes into fragment */
@@ -537,7 +527,7 @@ void dom_child_node_remove(dom_object *context)
537
527
return ;
538
528
}
539
529
540
- php_libxml_invalidate_node_list_cache_from_doc (context -> document -> ptr );
530
+ php_libxml_invalidate_node_list_cache_from_doc (child -> doc );
541
531
542
532
xmlUnlinkNode (child );
543
533
}
@@ -550,10 +540,9 @@ void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc)
550
540
551
541
/* Spec step 1 */
552
542
xmlNodePtr parentNode = child -> parent ;
553
- /* Spec step 2 */
554
- if (!parentNode ) {
555
- int stricterror = dom_get_strict_error (context -> document );
556
- php_dom_throw_error (HIERARCHY_REQUEST_ERR , stricterror );
543
+
544
+ /* Sanity check for fragment, includes spec step 2 */
545
+ if (UNEXPECTED (dom_sanity_check_node_list_for_insertion (context -> document , parentNode , nodes , nodesc ) != SUCCESS )) {
557
546
return ;
558
547
}
559
548
@@ -571,11 +560,8 @@ void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc)
571
560
viable_next_sibling = viable_next_sibling -> next ;
572
561
}
573
562
574
- if (UNEXPECTED (dom_sanity_check_node_list_for_insertion (context -> document , parentNode , nodes , nodesc ) != SUCCESS )) {
575
- return ;
576
- }
577
-
578
- php_libxml_invalidate_node_list_cache_from_doc (context -> document -> ptr );
563
+ xmlDocPtr doc = parentNode -> doc ;
564
+ php_libxml_invalidate_node_list_cache_from_doc (doc );
579
565
580
566
/* Spec step 4: convert nodes into fragment */
581
567
xmlNodePtr fragment = dom_zvals_to_fragment (context -> document , parentNode , nodes , nodesc );
@@ -586,7 +572,6 @@ void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc)
586
572
/* Spec step 5: perform the replacement */
587
573
588
574
xmlNodePtr newchild = fragment -> children ;
589
- xmlDocPtr doc = parentNode -> doc ;
590
575
591
576
/* Unlink it unless it became a part of the fragment.
592
577
* Freeing will be taken care of by the lifetime of the returned dom object. */
@@ -621,7 +606,7 @@ void dom_parent_node_replace_children(dom_object *context, zval *nodes, uint32_t
621
606
return ;
622
607
}
623
608
624
- php_libxml_invalidate_node_list_cache_from_doc (context -> document -> ptr );
609
+ php_libxml_invalidate_node_list_cache_from_doc (thisp -> doc );
625
610
626
611
dom_remove_all_children (thisp );
627
612
0 commit comments