diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb index 9aad7366..bd3b6856 100644 --- a/lib/rexml/parsers/xpathparser.rb +++ b/lib/rexml/parsers/xpathparser.rb @@ -47,7 +47,6 @@ def abbreviate(path_or_parsed) end components = [] component = nil - previous_op = nil while parsed.size > 0 op = parsed.shift case op @@ -119,10 +118,12 @@ def abbreviate(path_or_parsed) component << op.inspect component << ")" end - previous_op = op end - if components == [""] + case components + when [""] "/" + when ["", ""] + "//" else components.join("/") end diff --git a/test/parser/test_xpath.rb b/test/parser/test_xpath.rb index e06db656..9143d25c 100644 --- a/test/parser/test_xpath.rb +++ b/test/parser/test_xpath.rb @@ -16,6 +16,11 @@ def test_document abbreviate("/")) end + def test_descendant_or_self_only + assert_equal("//", + abbreviate("/descendant-or-self::node()/")) + end + def test_descendant_or_self_absolute assert_equal("//a/b", abbreviate("/descendant-or-self::node()/a/b"))