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

reschke 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 4b1616edbd Revert "OAK-11683: Optionally disallow registration of 
invalid namespace URIs (#2258)"
4b1616edbd is described below

commit 4b1616edbded9fc40604c18f92f6215cbd4c8fc0
Author: Julian Reschke <julian.resc...@gmx.de>
AuthorDate: Thu May 22 13:02:24 2025 +0100

    Revert "OAK-11683: Optionally disallow registration of invalid namespace 
URIs (#2258)"
    
    This reverts commit 9f3d003319bf2dc6138dff1c1d750ba82192170b.
---
 .../plugins/name/ReadWriteNamespaceRegistry.java   | 21 +++---------
 .../name/ReadWriteNamespaceRegistryTest.java       | 40 ++++++----------------
 2 files changed, 16 insertions(+), 45 deletions(-)

diff --git 
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
 
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
index 37adcaddf2..adea1bbad6 100644
--- 
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
+++ 
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
@@ -25,7 +25,6 @@ import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
 import org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,15 +38,7 @@ public abstract class ReadWriteNamespaceRegistry
 
     private static final Logger LOG = 
LoggerFactory.getLogger(ReadWriteNamespaceRegistry.class);
 
-    /**
-     * Feature flag to allow registering invalid namespace URIs (without a 
colon).
-     * Set the system property {@code oak.allowInvalidNamespaceUris} to {@code 
false} to disable this feature.
-     * Cannot be static in order to allow testing with different values.
-     */
-    private final boolean allowInvalidNamespaceUris = 
SystemPropertySupplier.create("oak.allowInvalidNamespaceUris", true)
-            .loggingTo(LOG).get();;
-
-    protected ReadWriteNamespaceRegistry(Root root) {
+    public ReadWriteNamespaceRegistry(Root root) {
         super(root);
     }
 
@@ -80,13 +71,11 @@ public abstract class ReadWriteNamespaceRegistry
 
         // sanity check for legal namespace names (excluding the "internal"
         // namespace, see OAK-74)
-        if (!NamespaceConstants.NAMESPACE_REP.equals(uri) && 
!uri.contains(":")) {
-            if (allowInvalidNamespaceUris) {
+        if (!NamespaceConstants.NAMESPACE_REP.equals(uri)) {
+            if (!uri.contains(":")) {
                 LOG.error("Registering invalid namespace name '" + uri + "' 
for prefix '" + prefix
-                            + "', please see 
https://s.apache.org/jcr-2.0-spec/3_Repository_Model.html#3.2.1%20Namespaces";,
-                            new Exception("call stack"));
-            } else {
-                throw new NamespaceException("Invalid namespace URI given: " + 
uri + ". It must contain a colon.");
+                        + "', please see 
https://developer.adobe.com/experience-manager/reference-materials/spec/jcr/2.0/3_Repository_Model.html#3.2.1%20Namespaces";,
+                        new Exception("call stack"));
             }
         }
 
diff --git 
a/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistryTest.java
 
b/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistryTest.java
index 42691289f3..30d70c9e46 100644
--- 
a/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistryTest.java
+++ 
b/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistryTest.java
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.oak.plugins.name;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -69,13 +68,13 @@ public class ReadWriteNamespaceRegistryTest extends 
OakBaseTest {
         assertEquals("mix", r.getPrefix("http://www.jcp.org/jcr/mix/1.0";));
         assertEquals("xml", 
r.getPrefix("http://www.w3.org/XML/1998/namespace";));
 
-        r.registerNamespace("p", "myscheme:n");
-        assertEquals(r.getURI("p"), "myscheme:n");
-        assertEquals(r.getPrefix("myscheme:n"), "p");
+        r.registerNamespace("p", "n");
+        assertEquals(r.getURI("p"), "n");
+        assertEquals(r.getPrefix("n"), "p");
 
-        r.registerNamespace("p2", "myscheme:n2");
-        assertEquals(r.getURI("p2"), "myscheme:n2");
-        assertEquals(r.getPrefix("myscheme:n2"), "p2");
+        r.registerNamespace("p2", "n2");
+        assertEquals(r.getURI("p2"), "n2");
+        assertEquals(r.getPrefix("n2"), "p2");
 
         // xml namespace check
         assertTrue(SetUtils.toSet(r.getPrefixes()).contains("xml"));
@@ -88,12 +87,13 @@ public class ReadWriteNamespaceRegistryTest extends 
OakBaseTest {
     }
 
     @Test
-    public void testInvalidNamespaceInDefaultMode() throws Exception {
+    public void testInvalidNamespace() throws Exception {
+        final ContentSession session = createContentSession();
+        final Root root = session.getLatestRoot();
+        NamespaceRegistry r = getNamespaceRegistry(session, root);
+
         LogCustomizer customLogs = 
LogCustomizer.forLogger("org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry").enable(Level.ERROR).create();
         try {
-            final ContentSession session = createContentSession();
-            final Root root = session.getLatestRoot();
-            NamespaceRegistry r = getNamespaceRegistry(session, root);
             customLogs.starting();
             r.registerNamespace("foo", "example.com");
             r.unregisterNamespace("foo");
@@ -103,24 +103,6 @@ public class ReadWriteNamespaceRegistryTest extends 
OakBaseTest {
         }
         finally {
             customLogs.finished();
-            
-        }
-    }
-
-    @Test
-    public void testInvalidNamespaceInStrictMode() {
-        String oldValue = System.setProperty("oak.allowInvalidNamespaceUris", 
"true");
-        try {
-            final ContentSession session = createContentSession();
-            final Root root = session.getLatestRoot();
-            NamespaceRegistry r = getNamespaceRegistry(session, root);
-            assertThrows(NamespaceException.class, () -> 
r.registerNamespace("foo", "example.com"));
-        } finally {
-            if (oldValue != null) {
-                System.setProperty("oak.allowInvalidNamespaceUris", oldValue);
-            } else {
-                System.clearProperty("oak.allowInvalidNamespaceUris");
-            }
         }
     }
 

Reply via email to