Skip to content

Commit

Permalink
Fall back to xmlGetProp when an attribute namespace cannot be found.
Browse files Browse the repository at this point in the history
This allows us to find namespaced properties in HTML documents.
Fixes #861.
  • Loading branch information
ender672 committed Mar 20, 2013
1 parent da8d089 commit 61101e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/nokogiri/xml_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions test/html/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<i foo:bar="baz"></i>'
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|
Expand Down

0 comments on commit 61101e5

Please sign in to comment.