Skip to content

Commit 4dd2084

Browse files
authored
Merge pull request #38 from OP-TED/TEDEFO-4538-remove-redundant-predicates
Fix XPathProcessor context predicate handling and update release notes
2 parents 2ed8b4b + dc8f377 commit 4dd2084

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# eForms Core Library 1.4.0 Release Notes
1+
# eForms Core Library 1.5.0 Release Notes
22

33
The eForms Core Library is a collection of utilities that are used by our sample applications as well as the EFX Toolkit for Java Developers.
44

55
## In this release
66

7-
This release adds the option to indicate a qualifier for SDK components. If there are 2 or more classes that have an @SdkComponent annotation with the same version and component type, this allows you to differentiate them and load the component with the matching qualifier.
7+
This release fixes an issue in the XPathProcessor that could cause a redundant predicate production when contextualising XPaths with multiple predicates.
88

9-
The versions of various dependencies was updated: ANTLR 4.13.1, JAXB 4.0.4, logback 1.5.3, ph-genericode 7.1.1.
9+
The versions of various dependencies was updated: Apache Commons IO 2.19.0, Apache Commons Lang 3.18.0, Jackson 2.18.3, logback 1.5.18.
1010

1111
## Download
1212

src/main/java/eu/europa/ted/eforms/xpath/XPathProcessor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,20 @@ private static String getContextualizedXpath(Queue<XPathStep> contextQueue,
7676
// we want to use a dot step with the predicate of the path.
7777
if (!contextQueue.isEmpty() && !pathQueue.isEmpty()
7878
&& pathQueue.peek().isSameAsOrNarrowerThan(contextQueue.peek())) {
79-
contextQueue.poll(); // consume the same step from the contextQueue
79+
// Consume the same step from the contextQueue and get its predicates
80+
List<String> contextPredicates = contextQueue.poll().getPredicates();
81+
// Keep only the predicates that are not in the context.
82+
String pathPredicates = pathQueue.poll().getPredicates().stream().filter(p -> !contextPredicates.contains(p)).collect(Collectors.joining(""));
8083
if (contextQueue.isEmpty()) {
8184
// Since there are no more steps in the contextQueue, the relative xpath should
8285
// start with a dot step to provide a context for the predicate.
83-
relativeXpath += "." + pathQueue.poll().getPredicateText();
86+
relativeXpath += "." + pathPredicates;
8487
} else {
8588
// Since there are more steps in the contextQueue which we will need to navigate back to,
86-
// using back-steps, we will use a back-step to provide context of the predicate.
89+
// using back-steps, we will use a back-step to provide context for the predicate.
8790
// This avoids an output that looks like ../.[predicate] which is valid but silly.
8891
contextQueue.poll(); // consume the step from the contextQueue
89-
relativeXpath += ".." + pathQueue.poll().getPredicateText();
92+
relativeXpath += ".." + pathPredicates;
9093
}
9194
}
9295

src/test/java/eu/europa/ted/eforms/xpath/XPathProcessorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void testIdentical() {
6565

6666
@Test
6767
void testIdentical_WithPredicates() {
68-
assertEquals(".[d = e][f = g]", contextualize("/a/b/c[d = e]", "/a/b/c[d = e][f = g]"));
68+
assertEquals(".[f = g]", contextualize("/a/b/c[d = e]", "/a/b/c[d = e][f = g]"));
6969
}
7070

7171
@Test
@@ -181,7 +181,7 @@ void testPredicateDifferent() {
181181

182182
@Test
183183
void testPredicateMoreInXpath() {
184-
assertEquals("..[e][f]/c/d", contextualize("/a/b[e]/c", "/a/b[e][f]/c/d"));
184+
assertEquals("..[f]/c/d", contextualize("/a/b[e]/c", "/a/b[e][f]/c/d"));
185185
}
186186

187187
@Test

0 commit comments

Comments
 (0)