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

baedke 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 36a32dcbc1 OAK-10624: o.a.j.o.namepath.JcrPathParser does not accept 
some valid local names containing '{' or '}'. (#1285)
36a32dcbc1 is described below

commit 36a32dcbc1e12142df47ca3b04c81d1c4cabde5c
Author: mbaedke <manfred.bae...@gmail.com>
AuthorDate: Thu May 23 15:47:36 2024 +0200

    OAK-10624: o.a.j.o.namepath.JcrPathParser does not accept some valid local 
names containing '{' or '}'. (#1285)
    
    Fixed issue and added test case.
    
    Co-authored-by: Julian Reschke <resc...@apache.org>
---
 .../jackrabbit/oak/namepath/JcrPathParser.java     | 22 ++++++++++++++++++----
 .../jackrabbit/oak/namepath/PathParserTest.java    |  1 -
 .../oak/namepath/impl/NamePathMapperImplTest.java  | 19 +++++--------------
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git 
a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
 
b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
index 0309d931a6..120527554b 100644
--- 
a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
+++ 
b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
@@ -228,8 +228,8 @@ public final class JcrPathParser {
                     if (state == STATE_PREFIX_START && lastPos == pos-1) {
                         // '{' marks the start of a uri enclosed in an 
expanded name
                         // instead of the usual namespace prefix, if it is
-                        // located at the beginning of a new segment.
-                        state = STATE_URI;
+                        // located at the beginning of a new segment and a '}' 
will follow.
+                        state = jcrPath.indexOf('}', pos) == -1 ? STATE_NAME : 
STATE_URI;
                     } else if (state == STATE_NAME_START || state == STATE_DOT 
|| state == STATE_DOTDOT) {
                         // otherwise it's part of the local name
                         state = STATE_NAME;
@@ -239,6 +239,13 @@ public final class JcrPathParser {
                 case '}':
                     if (state == STATE_URI) {
                         state = STATE_URI_END;
+                    } else if (state == STATE_PREFIX_START || state == 
STATE_DOT || state == STATE_DOTDOT) {
+                        state = STATE_PREFIX;
+                    } else if (state == STATE_NAME_START) {
+                        state = STATE_NAME;
+                    } else if (state == STATE_INDEX_END) {
+                        pathAwareListener.error("'" + c + "' not valid after 
index. '/' expected.");
+                        return false;
                     }
                     break;
 
@@ -251,9 +258,16 @@ public final class JcrPathParser {
                         state = STATE_INDEX;
                         name = jcrPath.substring(lastPos, pos - 1);
                         lastPos = pos;
-                        break;
                     }
-                    // intentionally no break, so we get the default treatment 
for all other states
+                    else if (state == STATE_PREFIX_START || state == STATE_DOT 
|| state == STATE_DOTDOT) {
+                        state = STATE_PREFIX;
+                    } else if (state == STATE_NAME_START) {
+                        state = STATE_NAME;
+                    } else if (state == STATE_INDEX_END) {
+                        pathAwareListener.error("'" + c + "' not valid after 
index. '/' expected.");
+                        return false;
+                    }
+                    break;
 
                 default:
                     if (state == STATE_PREFIX_START || state == STATE_DOT || 
state == STATE_DOTDOT) {
diff --git 
a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
 
b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
index 4bbe7f7077..81dc854a57 100755
--- 
a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
+++ 
b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
@@ -354,7 +354,6 @@ public class PathParserTest {
     }
 
     @Test
-    @Ignore //OAK-10624
     public void testCurlyBracketsInNames() throws RepositoryException {
         String path = "{a";
         TestListener listener = new TestListener(
diff --git 
a/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/impl/NamePathMapperImplTest.java
 
b/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/impl/NamePathMapperImplTest.java
index a6c5698cab..e9c86f0726 100644
--- 
a/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/impl/NamePathMapperImplTest.java
+++ 
b/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/impl/NamePathMapperImplTest.java
@@ -210,6 +210,11 @@ public class NamePathMapperImplTest {
                 "/parent/sub/childB4",
                 "/parent/sub/}childB5",
                 "/parent/sub/{childB6}",
+                "/parent/sub/{childB7",
+                "/parent/sub/{childB7",
+                "/parent/{",
+                "/parent/{childA1",
+                "/parent/{{childA2"
         };
 
         for (String path : paths) {
@@ -217,20 +222,6 @@ public class NamePathMapperImplTest {
         }
     }
     
-    @Test
-    public void testIllegalBracketsInPaths() throws Exception {
-        String[] paths = {
-                "/parent/sub/{childB7", 
-                "/parent/sub/{childB7",
-                "/parent/{", 
-                "/parent/{childA1", 
-                "/parent/{{childA2"        };
-
-        for (String path : paths) {
-            assertNull(npMapper.getOakPath(path));
-        }
-    }    
-
     @Test
     public void testWhitespace() {
         String[] paths = new String[] {

Reply via email to