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 ba...@apache.org on 2024/08/20 10:29:36 UTC
(jackrabbit-oak) branch 1.22 updated: OAK-10624: o.a.j.o.namepath.JcrPathParser does not accept some valid local names containing '{' or '}'. (#1285)
This is an automated email from the ASF dual-hosted git repository.
baedke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/1.22 by this push:
new fe7c58af2c OAK-10624: o.a.j.o.namepath.JcrPathParser does not accept some valid local names containing '{' or '}'. (#1285)
fe7c58af2c is described below
commit fe7c58af2cb9e41a425ee1172190f94c910945bb
Author: mbaedke <ma...@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 <re...@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 96a9eb30f1..e341eec116 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[] {