diff --git a/ext/nokogiri/xml_node.c b/ext/nokogiri/xml_node.c index 5baaf3bfc0..75d51559a8 100644 --- a/ext/nokogiri/xml_node.c +++ b/ext/nokogiri/xml_node.c @@ -772,19 +772,11 @@ static VALUE namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace) * * Set the +property+ to +value+ */ -static VALUE set(VALUE node_rb, VALUE property_name_rb, VALUE property_value_rb) +static VALUE set(VALUE self, VALUE property, VALUE value) { xmlNodePtr node, cur; - xmlChar* property_name ; - xmlAttrPtr property; - - Data_Get_Struct(node_rb, xmlNode, node); - - if (node->type != XML_ELEMENT_NODE) { - return(Qnil); // TODO: would raising an exception be more appropriate? - } - - property_name = (xmlChar *)StringValuePtr(property_name_rb); + xmlAttrPtr prop; + Data_Get_Struct(self, xmlNode, node); /* If a matching attribute node already exists, then xmlSetProp will destroy * the existing node's children. However, if Nokogiri has a node object @@ -792,9 +784,11 @@ static VALUE set(VALUE node_rb, VALUE property_name_rb, VALUE property_value_rb) * * We can avoid this by unlinking these nodes first. */ - property = xmlHasProp(node, property_name); - if (property && property->children) { - for (cur = property->children; cur; cur = cur->next) { + if (node->type != XML_ELEMENT_NODE) + return(Qnil); + prop = xmlHasProp(node, (xmlChar *)StringValuePtr(property)); + if (prop && prop->children) { + for (cur = prop->children; cur; cur = cur->next) { if (cur->_private) { nokogiri_root_node(cur); xmlUnlinkNode(cur); @@ -802,14 +796,10 @@ static VALUE set(VALUE node_rb, VALUE property_name_rb, VALUE property_value_rb) } } - xmlResetLastError(); - xmlSetStructuredErrorFunc(NULL, Nokogiri_error_silencer); - - xmlSetProp(node, property_name, (xmlChar *)StringValuePtr(property_value_rb)); - - xmlSetStructuredErrorFunc(NULL, NULL); + xmlSetProp(node, (xmlChar *)StringValuePtr(property), + (xmlChar *)StringValuePtr(value)); - return property_value_rb; + return value; } /*