diff options
author | Kouhei Sutou <[email protected]> | 2019-05-25 17:58:49 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2019-08-04 11:55:43 +0900 |
commit | 643344dc9460626617c9ce88f07b3ae0fed49150 (patch) | |
tree | f8fd1055293a32a7568467fd7c86af34412f8918 | |
parent | 5f78b138b10a6732676689f0f8690c1db16c1355 (diff) |
[ruby/rexml] xpath local_name: fix a bug that nil is returned for nonexistent case
It must be an empty string.
https://github.com/ruby/rexml/commit/81bc7cd4f5
-rw-r--r-- | lib/rexml/functions.rb | 5 | ||||
-rw-r--r-- | test/rexml/functions/test_base.rb (renamed from test/rexml/test_functions.rb) | 1 | ||||
-rw-r--r-- | test/rexml/functions/test_boolean.rb (renamed from test/rexml/test_functions_boolean.rb) | 0 | ||||
-rw-r--r-- | test/rexml/functions/test_local_name.rb | 44 | ||||
-rw-r--r-- | test/rexml/functions/test_number.rb (renamed from test/rexml/test_functions_number.rb) | 0 |
5 files changed, 48 insertions, 2 deletions
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 4b46b8e678..a0f4823ada 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -67,10 +67,11 @@ module REXML end # UNTESTED - def Functions::local_name( node_set=nil ) - get_namespace( node_set ) do |node| + def Functions::local_name(node_set=nil) + get_namespace(node_set) do |node| return node.local_name end + "" end def Functions::namespace_uri( node_set=nil ) diff --git a/test/rexml/test_functions.rb b/test/rexml/functions/test_base.rb index a00b25b2c1..74dc1a31de 100644 --- a/test/rexml/test_functions.rb +++ b/test/rexml/functions/test_base.rb @@ -3,6 +3,7 @@ require "test/unit/testcase" require "rexml/document" +# TODO: Split me module REXMLTests class FunctionsTester < Test::Unit::TestCase include REXML diff --git a/test/rexml/test_functions_boolean.rb b/test/rexml/functions/test_boolean.rb index b3e2117c10..b3e2117c10 100644 --- a/test/rexml/test_functions_boolean.rb +++ b/test/rexml/functions/test_boolean.rb diff --git a/test/rexml/functions/test_local_name.rb b/test/rexml/functions/test_local_name.rb new file mode 100644 index 0000000000..97c9e74852 --- /dev/null +++ b/test/rexml/functions/test_local_name.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: false + +require "test/unit" +require "rexml/document" +require "rexml/functions" + +module REXMLTests + class TestFunctionsLocalName < Test::Unit::TestCase + def setup + REXML::Functions.context = nil + end + + def test_one + document = REXML::Document.new(<<-XML) +<root xmlns:x="http://example.com/x/"> + <x:child/> +</root> + XML + node_set = document.root.children + assert_equal("child", REXML::Functions.local_name(node_set)) + end + + def test_multiple + document = REXML::Document.new(<<-XML) +<root xmlns:x="http://example.com/x/"> + <x:child1/> + <x:child2/> +</root> + XML + node_set = document.root.children + assert_equal("child1", REXML::Functions.local_name(node_set)) + end + + def test_nonexistent + assert_equal("", REXML::Functions.local_name([])) + end + + def test_context + document = REXML::Document.new("<root/>") + REXML::Functions.context = {node: document.root} + assert_equal("root", REXML::Functions.local_name()) + end + end +end diff --git a/test/rexml/test_functions_number.rb b/test/rexml/functions/test_number.rb index 84ec5c7ba7..84ec5c7ba7 100644 --- a/test/rexml/test_functions_number.rb +++ b/test/rexml/functions/test_number.rb |