diff --git a/ext/nokogiri/xml_node.c b/ext/nokogiri/xml_node.c index f880afc0070..b727965eba1 100644 --- a/ext/nokogiri/xml_node.c +++ b/ext/nokogiri/xml_node.c @@ -753,6 +753,8 @@ static VALUE get(VALUE self, VALUE rattribute) ns = xmlSearchNs(node->doc, node, (const xmlChar *)(prefix)); if (ns) { value = xmlGetNsProp(node, (xmlChar*)(attr_name), ns->href); + } else { + value = xmlGetProp(node, (xmlChar*)StringValuePtr(rattribute)); } } else { value = xmlGetNoNsProp(node, (xmlChar*)attribute); diff --git a/test/html/test_node.rb b/test/html/test_node.rb index 076787061be..f26275045f9 100644 --- a/test/html/test_node.rb +++ b/test/html/test_node.rb @@ -34,6 +34,14 @@ def test_get_attribute assert_match(/%22AGGA-KA-BOO!%22/, element.to_html) end + # The HTML parser ignores namespaces, so even properly declared namespaces + # are treated as as undeclared and have to be accessed via prefix:tagname + def test_ns_attribute + html = '' + doc = Nokogiri::HTML(html) + assert_equal 'baz', (doc%'i')['foo:bar'] + end + def test_css_path_round_trip doc = Nokogiri::HTML(File.read(HTML_FILE)) %w{ #header small div[2] div.post body }.each do |css_sel|