mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
rexml: Fix XPath bug of //#{ELEMENT_NAME}[#{POSITION}]
The position should be counted for each nodeset but the previous implementation counts position for union-ed nodeset. For example, "/a/*/*[1]" should be matched to "<c1/>" and "<c2/>" with the following XML. <a> <b> <c1/> </b> <b> <c2/> </b> </a> But the previous implementation just returns only "<c1/>". * lib/rexml/element.rb (REXML::Attributes#each_attribute): Support Enumerator for no block use. * lib/rexml/element.rb (REXML::Attributes#each): Support Enumerator for no block use. * lib/rexml/functions.rb (REXML::Functions.string): Support NaN again. * lib/rexml/xpath_parser.rb: Re-implement "Step" evaluator. It should evaluate "AxisSpecifier", "NodeTest" and "Predicate" in one step to respect position for each nodeset. * test/rexml/test_jaxen.rb: Enable more tests. Remained tests should be also enabled but it'll not be near future. * test/rexml/xpath/test_base.rb: Fix expected value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4d15e619eb
commit
7a6f34103d
5 changed files with 527 additions and 348 deletions
|
@ -1033,6 +1033,7 @@ module REXML
|
|||
# p attr.expanded_name+" => "+attr.value
|
||||
# }
|
||||
def each_attribute # :yields: attribute
|
||||
return to_enum(__method__) unless block_given?
|
||||
each_value do |val|
|
||||
if val.kind_of? Attribute
|
||||
yield val
|
||||
|
@ -1048,6 +1049,7 @@ module REXML
|
|||
# doc = Document.new '<a x="1" y="2"/>'
|
||||
# doc.root.attributes.each {|name, value| p name+" => "+value }
|
||||
def each
|
||||
return to_enum(__method__) unless block_given?
|
||||
each_attribute do |attr|
|
||||
yield [attr.expanded_name, attr.value]
|
||||
end
|
||||
|
|
|
@ -154,12 +154,16 @@ module REXML
|
|||
case object
|
||||
when Array
|
||||
string(object[0])
|
||||
when Numeric
|
||||
integer = object.to_i
|
||||
if object == integer
|
||||
"%d" % integer
|
||||
when Float
|
||||
if object.nan?
|
||||
"NaN"
|
||||
else
|
||||
object.to_s
|
||||
integer = object.to_i
|
||||
if object == integer
|
||||
"%d" % integer
|
||||
else
|
||||
object.to_s
|
||||
end
|
||||
end
|
||||
when nil
|
||||
""
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -24,14 +24,17 @@ module REXMLTests
|
|||
# document() function for XSLT isn't supported
|
||||
def _test_message ; process_test_case("message") ; end
|
||||
def test_moreover ; process_test_case("moreover") ; end
|
||||
def _test_much_ado ; process_test_case("much_ado") ; end
|
||||
def _test_namespaces ; process_test_case("namespaces") ; end
|
||||
def _test_nitf ; process_test_case("nitf") ; end
|
||||
def test_much_ado ; process_test_case("much_ado") ; end
|
||||
def test_namespaces ; process_test_case("namespaces") ; end
|
||||
def test_nitf ; process_test_case("nitf") ; end
|
||||
# Exception should be considered
|
||||
def _test_numbers ; process_test_case("numbers") ; end
|
||||
def test_pi ; process_test_case("pi") ; end
|
||||
def test_pi2 ; process_test_case("pi2") ; end
|
||||
def test_simple ; process_test_case("simple") ; end
|
||||
# TODO: namespace node is needed
|
||||
def _test_testNamespaces ; process_test_case("testNamespaces") ; end
|
||||
# document() function for XSLT isn't supported
|
||||
def _test_text ; process_test_case("text") ; end
|
||||
def test_underscore ; process_test_case("underscore") ; end
|
||||
def _test_web ; process_test_case("web") ; end
|
||||
|
|
|
@ -713,7 +713,7 @@ module REXMLTests
|
|||
XML
|
||||
d = REXML::Document.new( source )
|
||||
r = REXML::XPath.match( d, %q{/a/*/*[1]} )
|
||||
assert_equal(["1"],
|
||||
assert_equal(["1", "3"],
|
||||
r.collect {|element| element.attribute("id").value})
|
||||
end
|
||||
|
||||
|
@ -849,7 +849,7 @@ module REXMLTests
|
|||
EOL
|
||||
d = REXML::Document.new( string )
|
||||
cs = XPath.match( d, '/a/*/*[1]' )
|
||||
assert_equal(["c1"], cs.collect(&:name))
|
||||
assert_equal(["c1", "c2"], cs.collect(&:name))
|
||||
end
|
||||
|
||||
def test_sum
|
||||
|
|
Loading…
Add table
Reference in a new issue