Skip to content
Browse files

[FEATURE] XML::Node#[]= should stringify values

  • Loading branch information...
1 parent 44d1c3e commit 9973cc4cdfcdf1e1b30eed2daed0d57b69872530 @benlangfeld benlangfeld committed Jul 13, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/nokogiri/xml/node.rb
  2. +8 −0 test/xml/test_node.rb
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
8 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'])

0 comments on commit 9973cc4

Please sign in to comment.
Something went wrong with that request. Please try again.