Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #729 from adhearsion/feature/misc

XPath lookup with namespaces with hash keys and XML::Node#[]= should stringify values
  • Loading branch information...
commit dae5dcba9f3c39896fbd7cfa995d3df40cca9208 2 parents 3bea293 + 9973cc4
@flavorjones flavorjones authored
View
2  lib/nokogiri/xml/node.rb
@@ -258,7 +258,7 @@ def [] name
###
# Set the attribute value for the attribute +name+ to +value+
def []= name, value
- set name.to_s, value
+ set name.to_s, value.to_s
end
###
View
2  lib/nokogiri/xml/xpath_context.rb
@@ -6,7 +6,7 @@ class XPathContext
# Register namespaces in +namespaces+
def register_namespaces(namespaces)
namespaces.each do |k, v|
- k = k.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
+ k = k.to_s.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
register_ns(k, v)
end
end
View
24 test/xml/test_node.rb
@@ -724,6 +724,14 @@ def test_set_property
assert_equal('bar', node['foo'])
end
+ def test_set_property_non_string
+ assert node = @xml.search('//address').first
+ node['foo'] = 1
+ assert_equal('1', node['foo'])
+ node['foo'] = false
+ assert_equal('false', node['foo'])
+ end
+
def test_attributes
assert node = @xml.search('//address').first
assert_nil(node['asdfasdfasdf'])
@@ -835,6 +843,22 @@ def test_namespace_search_with_xpath_and_hash
assert_equal 1, tires.length
end
+ def test_namespace_search_with_xpath_and_hash_with_symbol_keys
+ xml = Nokogiri::XML.parse(<<-eoxml)
+ <root>
+ <car xmlns:part="http://general-motors.com/">
+ <part:tire>Michelin Model XGV</part:tire>
+ </car>
+ <bicycle xmlns:part="http://schwinn.com/">
+ <part:tire>I'm a bicycle tire!</part:tire>
+ </bicycle>
+ </root>
+ eoxml
+
+ tires = xml.xpath('//bike:tire', :bike => 'http://schwinn.com/')
+ assert_equal 1, tires.length
+ end
+
def test_namespace_search_with_css
xml = Nokogiri::XML.parse(<<-eoxml)
<root>
Please sign in to comment.
Something went wrong with that request. Please try again.