You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by nf...@apache.org on 2024/11/29 07:39:38 UTC
(jackrabbit-oak) branch trunk updated: OAK-11285 - Check if paths used in included/excluded Paths are absolute and fail if they are not (#1878)
This is an automated email from the ASF dual-hosted git repository.
nfsantos pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new ecfd1f6e12 OAK-11285 - Check if paths used in included/excluded Paths are absolute and fail if they are not (#1878)
ecfd1f6e12 is described below
commit ecfd1f6e12615d7bc077fe3d6f11a220240f5a23
Author: Nuno Santos <ns...@adobe.com>
AuthorDate: Fri Nov 29 08:39:32 2024 +0100
OAK-11285 - Check if paths used in included/excluded Paths are absolute and fail if they are not (#1878)
---
.../secondary/SecondaryStoreObserverTest.java | 2 +-
.../jackrabbit/oak/spi/filter/PathFilter.java | 12 +++++++++-
.../jackrabbit/oak/spi/filter/PathFilterTest.java | 26 ++++++++++++++++++++++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java
index df07c6bf38..dee3e0b948 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java
@@ -95,7 +95,7 @@ public class SecondaryStoreObserverTest {
@Test
public void childNodeChangedAndExclude() throws Exception{
- PathFilter pathFilter = new PathFilter(of("/a"), of("a/b"));
+ PathFilter pathFilter = new PathFilter(of("/a"), of("/a/b"));
SecondaryStoreObserver observer = createBuilder(pathFilter).buildObserver();
primary.addObserver(observer);
diff --git a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/spi/filter/PathFilter.java b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/spi/filter/PathFilter.java
index dd1d803588..08212db50e 100644
--- a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/spi/filter/PathFilter.java
+++ b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/spi/filter/PathFilter.java
@@ -122,7 +122,9 @@ public class PathFilter {
* @param includes list of paths which should be included
* @param excludes list of paths which should not be included
*/
- public PathFilter(Iterable<String> includes, Iterable<String> excludes) {
+ public PathFilter(@NotNull Iterable<String> includes, @NotNull Iterable<String> excludes) {
+ checkPathsAreAbsolute(includes, "included");
+ checkPathsAreAbsolute(excludes, "excluded");
Set<String> includeCopy = CollectionUtils.toSet(includes);
Set<String> excludeCopy = CollectionUtils.toSet(excludes);
PathUtils.unifyInExcludes(includeCopy, excludeCopy);
@@ -195,4 +197,12 @@ public class PathFilter {
}
return false;
}
+
+ private static void checkPathsAreAbsolute(Iterable<String> paths, String pathType) {
+ for (String path : paths) {
+ if (!PathUtils.isAbsolute(path)) {
+ throw new IllegalStateException("Invalid path in " + pathType + " paths list: " + path + ". Paths must be absolute.");
+ }
+ }
+ }
}
diff --git a/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/spi/filter/PathFilterTest.java b/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/spi/filter/PathFilterTest.java
index 37c62ecea0..c64d21af90 100644
--- a/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/spi/filter/PathFilterTest.java
+++ b/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/spi/filter/PathFilterTest.java
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
@@ -131,6 +132,31 @@ public class PathFilterTest {
}
}
+ @Test
+ public void checkPathsAreAbsoluteOk() {
+ new PathFilter(List.of("/a", "/b", "/c"), List.of());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void invalidIncludedStartsWithEmpty() {
+ new PathFilter(List.of( "/a", " /b"), List.of());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void invalidExcludedStartsWithEmpty() {
+ new PathFilter(List.of(), List.of( "/a", " /b"));
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void invalidIncludedDoesNotStartWithSlash() {
+ new PathFilter(List.of("a"), List.of());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void invalidExcludedDoesNotStartWithSlash() {
+ new PathFilter(List.of(), List.of("a"));
+ }
+
@Test
public void getStringsLenientNodeBuilder_MultipleValues() {
NodeBuilder root = EMPTY_NODE.builder();