You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/09/05 12:54:28 UTC

(sling-org-apache-sling-jcr-repoinit) branch SLING-12439 created (now 099778f)

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

reschke pushed a change to branch SLING-12439
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git


      at 099778f  SLING-12439: repoinit allows invalid namespace names (URIs) - log warnings

This branch includes the following new commits:

     new 099778f  SLING-12439: repoinit allows invalid namespace names (URIs) - log warnings

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(sling-org-apache-sling-jcr-repoinit) 01/01: SLING-12439: repoinit allows invalid namespace names (URIs) - log warnings

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch SLING-12439
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 099778f3bf8251b3d67fa111b86656f03648dbcd
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Fri Sep 5 13:54:07 2025 +0100

    SLING-12439: repoinit allows invalid namespace names (URIs) - log warnings
---
 .../sling/jcr/repoinit/impl/NamespacesVisitor.java |  5 ++++-
 .../sling/jcr/repoinit/RegisterNamespacesTest.java | 25 ++++++++++++++++++----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java
index b4d0ebb..205e858 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java
@@ -34,12 +34,15 @@ class NamespacesVisitor extends DoNothingVisitor {
     public NamespacesVisitor(Session s) {
         super(s);
     }
-    
+
     @Override
     public void visitRegisterNamespace(RegisterNamespace rn) {
         try {
             final NamespaceRegistry reg = session.getWorkspace().getNamespaceRegistry();
             log.info("Registering namespace from {}", rn);
+            if (!rn.getURI().contains(":")) {
+                log.warn("{} is not a valid namespace name (URI); certain repository operations using this namespace may fail", rn.getURI());
+            }
             reg.registerNamespace(rn.getPrefix(), rn.getURI());
         } catch(Exception e) {
             report(e, "Unable to register namespace from " + rn);
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java
index 004af9b..7a2d735 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java
@@ -36,19 +36,24 @@ public class RegisterNamespacesTest {
 
     @Rule
     public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
-    
+
     private TestUtil U;
     private NamespaceRegistry ns;
-    
+
     private static final String TEST_ID = UUID.randomUUID().toString();
+    // URN
     private static final String NS1 = "uri:ns:test1:" + TEST_ID;
+    // HTTP URI
     private static final String NS2 = "http://example.com/ns/" + TEST_ID;
-   
+    // not a namespace name (URI) at all
+    private static final String NS3 = TEST_ID;
+
     @Before
     public void setup() throws RepositoryException, RepoInitParsingException {
         U = new TestUtil(context);
         U.parseAndExecute("register namespace (one) " + NS1);
         U.parseAndExecute("register namespace (two) " + NS2);
+        U.parseAndExecute("register namespace (three) " + NS3);
         ns = U.getAdminSession().getWorkspace().getNamespaceRegistry();
     }
 
@@ -56,9 +61,21 @@ public class RegisterNamespacesTest {
     public void NS1registered() throws Exception {
         assertEquals(NS1, ns.getURI("one"));
     }
-    
+
     @Test
     public void NS2registered() throws Exception {
         assertEquals(NS2, ns.getURI("two"));
     }
+
+    @Test
+    public void NS3registered() throws Exception {
+        // this will succeed although it is wrong
+        // (repoinit will log a warning though)
+        assertEquals(NS3, ns.getURI("three"));
+    }
+
+    @Test(expected = RepoInitParsingException.class)
+    public void EmptyNamespaceName() throws RepoInitParsingException, RepositoryException {
+        U.parseAndExecute("register namespace (four)");
+    }
 }