Skip to content

Commit 899be1d

Browse files
committed
[bugfix] Fix an issue in NodePath#toString()
1 parent 004d5dc commit 899be1d

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed

exist-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,8 @@
950950
<include>src/main/java/org/exist/storage/IndexSpec.java</include>
951951
<include>src/main/java/org/exist/storage/NativeBroker.java</include>
952952
<include>src/main/java/org/exist/storage/NativeValueIndex.java</include>
953+
<include>src/main/java/org/exist/storage/NodePath.java</include>
954+
<include>src/test/java/org/exist/storage/NodePathTest.java</include>
953955
<include>src/main/java/org/exist/storage/ProcessMonitor.java</include>
954956
<include>src/main/java/org/exist/storage/StorageAddress.java</include>
955957
<include>src/test/java/org/exist/storage/RecoveryTest.java</include>
@@ -1311,6 +1313,8 @@
13111313
<exclude>src/test/java/org/exist/storage/MoveCollectionTest.java</exclude>
13121314
<exclude>src/main/java/org/exist/storage/NativeBroker.java</exclude>
13131315
<exclude>src/main/java/org/exist/storage/NativeValueIndex.java</exclude>
1316+
<exclude>src/main/java/org/exist/storage/NodePath.java</exclude>
1317+
<exclude>src/test/java/org/exist/storage/NodePathTest.java</exclude>
13141318
<exclude>src/main/java/org/exist/storage/ProcessMonitor.java</exclude>
13151319
<exclude>src/test/java/org/exist/storage/RecoverBinaryTest.java</exclude>
13161320
<exclude>src/test/java/org/exist/storage/RecoverXmlTest.java</exclude>

exist-core/src/main/java/org/exist/storage/NodePath.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -242,17 +266,21 @@ public final boolean match(final NodePath other, int j) {
242266
@Override
243267
public String toString() {
244268
final StringBuilder buf = new StringBuilder();
269+
boolean prevSkip = false;
245270
for (int i = 0; i < pos; i++) {
246-
247-
if (!(SKIP.equals(components[i]) || (i > 0 && SKIP.equals(components[i - 1])))) {
248-
buf.append("/");
271+
final QName component = components[i];
272+
if (component != NodePath.SKIP && !component.equals(NodePath.SKIP)) {
273+
if (!prevSkip) {
274+
buf.append("/");
275+
}
276+
prevSkip = false;
277+
} else {
278+
prevSkip = true;
249279
}
250-
251-
if (components[i].getNameType() == ElementValue.ATTRIBUTE) {
280+
if (component.getNameType() == ElementValue.ATTRIBUTE) {
252281
buf.append("@");
253282
}
254-
255-
buf.append(components[i]);
283+
buf.append(component);
256284
}
257285
return buf.toString();
258286
}

exist-core/src/test/java/org/exist/storage/NodePathTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -90,6 +114,12 @@ public void appendFromEmpty() {
90114
assertEquals("/a/b/c/d", path.toString());
91115
path.append(new NodePath(null, "/1/2/3"));
92116
assertEquals("/a/b/c/d/1/2/3", path.toString());
117+
118+
path = new NodePath();
119+
path.addComponent(NodePath.SKIP);
120+
path.addComponent(new QName("lemma", "", "", ElementValue.ATTRIBUTE));
121+
assertEquals("//@lemma", path.toString());
122+
93123
}
94124

95125
@Test
@@ -108,6 +138,10 @@ public void appendFromNonEmpty() {
108138
assertEquals("/a/b/c/d", path.toString());
109139
path.append(new NodePath(null, "/1/2/3"));
110140
assertEquals("/a/b/c/d/1/2/3", path.toString());
141+
142+
path = new NodePath(NodePath.SKIP);
143+
path.addComponent(new QName("lemma", "", "", ElementValue.ATTRIBUTE));
144+
assertEquals("//@lemma", path.toString());
111145
}
112146

113147
@Test

0 commit comments

Comments
 (0)