Skip to content

Commit 957e50e

Browse files
committed
xpath abbreviate: add a special case for only "//"
1 parent 3ddbdfc commit 957e50e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/rexml/parsers/xpathparser.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def abbreviate(path_or_parsed)
4747
end
4848
components = []
4949
component = nil
50-
previous_op = nil
5150
while parsed.size > 0
5251
op = parsed.shift
5352
case op
@@ -119,10 +118,12 @@ def abbreviate(path_or_parsed)
119118
component << op.inspect
120119
component << ")"
121120
end
122-
previous_op = op
123121
end
124-
if components == [""]
122+
case components
123+
when [""]
125124
"/"
125+
when ["", ""]
126+
"//"
126127
else
127128
components.join("/")
128129
end

test/parser/test_xpath.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def test_document
1616
abbreviate("/"))
1717
end
1818

19+
def test_descendant_or_self_only
20+
assert_equal("//",
21+
abbreviate("/descendant-or-self::node()/"))
22+
end
23+
1924
def test_descendant_or_self_absolute
2025
assert_equal("//a/b",
2126
abbreviate("/descendant-or-self::node()/a/b"))

0 commit comments

Comments
 (0)