diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-22 08:09:04 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-22 08:09:04 +0000 |
commit | 4d15e619eb1838daafd1510e86c1c8076fb9b227 (patch) | |
tree | 52009b7046146ad093bcd91db9b7b22f7e38bb0b /test/rexml/test_core.rb | |
parent | b252d8ada355ab729a545274e107d3f082f1fde6 (diff) | |
download | ruby-4d15e619eb1838daafd1510e86c1c8076fb9b227.tar.gz |
rexml: Fix XPath bug of /#{ELEMENT_NAME}
It doesn't mean that all elements which name "ELEMENT_NAME" with any
namespace URI including null namespace URI. It means that all elements
which name "ELEMENT_NAME" with null namespace URI.
https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-NodeTest
> if the QName does not have a prefix, then the namespace URI is null
> (this is the same way attribute names are expanded).
We need to use "*[local-name()='#{ELEMENT_NAME}']" for all elements
which name "ELEMENT_NAME" with any namespace URI including null
namespace URI in XPath 1.0. But it's inconvenient. So this change
includes "*:#{LOCAL_NAME}" syntax support that is introduced since
XPath 2.0.
* lib/rexml/parsers/xpathparser.rb: Support "*:#{LOCAL_NAME}" syntax that
is introduced since XPath 2.0.
* lib/rexml/xpath_parser.rb:
* Fix namespace URI processing for "#{ELEMENT_NAME}". Now,
"#{ELEMENT_NAME}" doesn't accept elements with null namespace URI.
* Add "*:#{LOCAL_NAME}" support.
* test/rexml/test_contrib.rb,
test/rexml/test_core.rb,
test/rexml/xpath/test_base.rb: Follow this change.
* test/rexml/test_jaxen.rb: Fix namespace processing.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rexml/test_core.rb')
-rw-r--r-- | test/rexml/test_core.rb | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/test/rexml/test_core.rb b/test/rexml/test_core.rb index 0071063128..b2e5299f39 100644 --- a/test/rexml/test_core.rb +++ b/test/rexml/test_core.rb @@ -877,18 +877,18 @@ EOL EOL # The most common case. People not caring about the namespaces much. - assert_equal( "XY", XPath.match( doc, "/test/a/text()" ).join ) - assert_equal( "XY", XPath.match( doc, "/test/x:a/text()" ).join ) + assert_equal( "XY", XPath.match( doc, "/*:test/*:a/text()" ).join ) + assert_equal( "XY", XPath.match( doc, "/*:test/x:a/text()" ).join ) # Surprising? I don't think so, if you believe my definition of the "common case" - assert_equal( "XYZ", XPath.match( doc, "//a/text()" ).join ) + assert_equal( "XYZ", XPath.match( doc, "//*:a/text()" ).join ) # These are the uncommon cases. Namespaces are actually important, so we define our own # mappings, and pass them in. assert_equal( "XY", XPath.match( doc, "/f:test/f:a/text()", { "f" => "1" } ).join ) # The namespaces are defined, and override the original mappings - assert_equal( "", XPath.match( doc, "/test/a/text()", { "f" => "1" } ).join ) + assert_equal( "XY", XPath.match( doc, "/*:test/*:a/text()", { "f" => "1" } ).join ) assert_equal( "", XPath.match( doc, "/x:test/x:a/text()", { "f" => "1" } ).join ) - assert_equal( "", XPath.match( doc, "//a/text()", { "f" => "1" } ).join ) + assert_equal( "XYZ", XPath.match( doc, "//*:a/text()", { "f" => "1" } ).join ) end def test_processing_instruction @@ -1390,8 +1390,8 @@ ENDXML def test_ticket_102 doc = REXML::Document.new '<doc xmlns="ns"><item name="foo"/></doc>' - assert_equal( "foo", doc.root.elements["item"].attribute("name","ns").to_s ) - assert_equal( "item", doc.root.elements["item[@name='foo']"].name ) + assert_equal( "foo", doc.root.elements["*:item"].attribute("name","ns").to_s ) + assert_equal( "item", doc.root.elements["*:item[@name='foo']"].name ) end def test_ticket_14 @@ -1420,11 +1420,11 @@ ENDXML doc = REXML::Document.new( '<doc xmlns="ns" xmlns:phantom="ns"><item name="foo">text</item></doc>' ) - assert_equal 'text', doc.text( "/doc/item[@name='foo']" ) + assert_equal 'text', doc.text( "/*:doc/*:item[@name='foo']" ) assert_equal "name='foo'", - doc.root.elements["item"].attribute("name", "ns").inspect + doc.root.elements["*:item"].attribute("name", "ns").inspect assert_equal "<item name='foo'>text</item>", - doc.root.elements["item[@name='foo']"].to_s + doc.root.elements["*:item[@name='foo']"].to_s end def test_ticket_135 |