This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ca49851 SLING-12806 Prevent creating a resource with a name only 
consisting out of dots
5ca49851 is described below

commit 5ca4985198b23e092f66a928c5ceece5c4889ef6
Author: Konrad Windszus <[email protected]>
AuthorDate: Wed May 28 12:36:32 2025 +0200

    SLING-12806 Prevent creating a resource with a name only consisting out
    of dots
---
 .../apache/sling/resourceresolver/impl/ResourceResolverImpl.java  | 5 ++++-
 .../sling/resourceresolver/impl/ResourceResolverImplTest.java     | 8 +++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
index 07c61b30..f36aa205 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
@@ -1055,7 +1055,10 @@ public class ResourceResolverImpl extends SlingAdaptable 
implements ResourceReso
         }
         // name should be a name not a path
         if (name.indexOf("/") != -1) {
-            throw new IllegalArgumentException("Name should not contain a 
slash: " + name);
+            throw new IllegalArgumentException("Name must not contain a slash: 
" + name);
+        }
+        if (name.chars().allMatch(c -> c == '.')) {
+            throw new IllegalArgumentException("Name must not only consist of 
dots: " + name);
         }
         final String path;
         if (parent.getPath().equals("/")) {
diff --git 
a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
 
b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
index 38c00a2a..abdb2427 100644
--- 
a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
+++ 
b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
@@ -521,7 +521,13 @@ public class ResourceResolverImplTest {
             // correct
         }
         try {
-            this.resResolver.create(r, "a", null);
+            this.resResolver.create(r, "....", null);
+            fail("Only dots in name should throw illegal argument exception");
+        } catch (final IllegalArgumentException pe) {
+            // correct
+        }
+        try {
+            this.resResolver.create(r, "a.b", null);
             fail("This should be unsupported.");
         } catch (final UnsupportedOperationException uoe) {
             // correct

Reply via email to