File tree 3 files changed +27
-2
lines changed
3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -652,7 +652,7 @@ public class XmlNode extends RubyObject
652
652
Node attribute = attributes .item (j );
653
653
String localName = attribute .getLocalName ();
654
654
if (localName == null ) {
655
- continue ;
655
+ localName = attribute . getNodeName () ;
656
656
}
657
657
if (localName .equals (name )) {
658
658
return getCachedNodeOrCreate (context .runtime , attribute );
Original file line number Diff line number Diff line change @@ -23,7 +23,15 @@ def test_to_a
23
23
24
24
def test_attr
25
25
node = @html . at ( "div.baz" )
26
- assert_equal ( node [ "class" ] , node . attr ( "class" ) )
26
+ assert_equal ( "baz" , node [ "class" ] )
27
+ assert_equal ( "baz" , node . attr ( "class" ) )
28
+ end
29
+
30
+ def test_attribute
31
+ # https://github.com/sparklemotion/nokogiri/issues/3487
32
+ node = @html . at ( "div.baz" )
33
+ refute_nil ( node . attribute ( "class" ) )
34
+ assert_equal ( "baz" , node . attribute ( "class" ) . value )
27
35
end
28
36
29
37
def test_get_attribute
Original file line number Diff line number Diff line change @@ -129,6 +129,23 @@ class TestNodeSet < Nokogiri::TestCase
129
129
end
130
130
end
131
131
132
+ it "#attr on XML gets attribute from first node" do
133
+ doc = Nokogiri ::XML ( "<root><child name='ruby' /><child name='python' /></root>" )
134
+ children = doc . css ( "child" )
135
+
136
+ refute_nil ( children . attr ( "name" ) )
137
+ assert_equal ( children . first . attribute ( "name" ) , children . attr ( "name" ) )
138
+ end
139
+
140
+ it "#attr on HTML gets attribute from first node" do
141
+ # https://github.com/sparklemotion/nokogiri/issues/3487
142
+ doc = Nokogiri ::HTML ( "<root><child name='ruby' /><child name='python' /></root>" )
143
+ children = doc . css ( "child" )
144
+
145
+ refute_nil ( children . attr ( "name" ) )
146
+ assert_equal ( children . first . attribute ( "name" ) , children . attr ( "name" ) )
147
+ end
148
+
132
149
it "#attribute with no args gets attribute from first node" do
133
150
list . first [ "foo" ] = "bar"
134
151
assert_equal ( list . first . attribute ( "foo" ) , list . attribute ( "foo" ) )
You can’t perform that action at this time.
0 commit comments