Skip to content

Commit

Permalink
Fix sparklemotion#391 by restoring null prefix instead of default
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecuyer committed Nov 15, 2015
1 parent 786644e commit 561e2ce
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ext/nokogiri/xml_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
{
VALUE reparented_obj ;
xmlNodePtr reparentee, pivot, reparented, next_text, new_next_text, parent ;
int prefix_was_null;

if(!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode))
rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
Expand Down Expand Up @@ -238,8 +239,19 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
xmlResetLastError();
xmlSetStructuredErrorFunc((void *)rb_iv_get(DOC_RUBY_OBJECT(pivot->doc), "@errors"), Nokogiri_error_array_pusher);

if (reparentee->ns != NULL && reparentee->ns->prefix == NULL) {
prefix_was_null = 1;
}

/*
* xmlDocCopyNode set wrong namespace (default) to root node
*/
reparentee = xmlDocCopyNode(reparentee, pivot->doc, 1) ;

if (reparentee->ns != NULL && reparentee->ns->prefix != NULL && prefix_was_null == 1) {
reparentee->ns->prefix = NULL;
}

xmlSetStructuredErrorFunc(NULL, NULL);

if (! reparentee) {
Expand Down

0 comments on commit 561e2ce

Please sign in to comment.