Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.1
-
None
-
None
-
Mac OS X 10.6.2
-
Patch
Description
When iterating over a collection of GPath Attributes I'm seeing the wrong value being returned for the "Attribute.name()" method. The issue seems to be in the implementation of the "groovy.util.slurpersupport.Attributes.iterator()" method when constructing a new Attribute. It uses the "attributeName" field which holds the name of the attribute minus the '@' character. The "Attribute.name()" method is expecting the first character in the name to be '@' as well and throws it away. This leads to the first character in the attribute name going missing.
I've attached a patch which shows one possible fix to the issue in Attributes.java. It also modifies GpathSyntaxTestSupport.groovy to add some Unit Tests for this issue.
The following code demonstrates the problem I'm seeing.
def xml = ''' <people> <person age="20">John</person> <person age="25">Jane</person> </people> ''' def p = new XmlSlurper().parseText(xml) p.person.each { println it.@age.name() } p.person.@age.each { println it.name() }
Running the above gives the following output:
age
age
ge
ge