You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2021/05/04 13:23:53 UTC
[felix-dev] branch master updated: FELIX-6406 : Exception when
parsing multi-line configurations
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 2b02482 FELIX-6406 : Exception when parsing multi-line configurations
2b02482 is described below
commit 2b02482d41dd02a97bccedd644a0c268008487bf
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 4 15:23:39 2021 +0200
FELIX-6406 : Exception when parsing multi-line configurations
---
.../apache/felix/cm/file/ConfigurationHandler.java | 4 +--
.../felix/cm/file/ConfigurationHandlerTest.java | 40 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java b/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
index 0883987..5712599 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
@@ -297,7 +297,7 @@ public class ConfigurationHandler
token = 0;
while ( nextToken( pr, true ) == TOKEN_NAME )
{
- String key = tokenValue;
+ String key = tokenValue.trim();
// expect equal sign
if ( nextToken( pr, false ) != TOKEN_EQ )
@@ -559,7 +559,6 @@ public class ConfigurationHandler
case -1: // fall through
// separator token
- case TOKEN_SPACE:
case TOKEN_EQ:
case TOKEN_VAL_CLOS:
pr.unread( c );
@@ -650,7 +649,6 @@ public class ConfigurationHandler
return c;
}
-
private int read( PushbackReader pr ) throws IOException
{
int c = pr.read();
diff --git a/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java b/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java
index 831b225..b1effc5 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
@@ -48,6 +49,36 @@ public class ConfigurationHandlerTest {
" # custom datastore\n" +
PAR_2 + "=B\"" + VAL_2 + "\"\n";
+ private static final String MULTI_LINE_CONFIG = "# Licensed to the Apache Software Foundation (ASF) under one or more\n"
+ + "# contributor license agreements. See the NOTICE file distributed with this\n"
+ + "# work for additional information regarding copyright ownership. The ASF\n"
+ + "# licenses this file to You under the Apache License, Version 2.0 (the\n"
+ + "# \"License\"); you may not use this file except in compliance with the License.\n"
+ + "# You may obtain a copy of the License at\n"
+ + "#\n"
+ + "# http://www.apache.org/licenses/LICENSE-2.0\n"
+ + "#\n"
+ + "# Unless required by applicable law or agreed to in writing, software\n"
+ + "# distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n"
+ + "# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n"
+ + "# License for the specific language governing permissions and limitations under\n"
+ + "# the License.\n"
+ + "\n"
+ + "scripts=[\\\n"
+ + " \"create service user test-user\n"
+ + " set ACL for test-user\n"
+ + " allow jcr:read on /conf\n"
+ + " end\",\\\n"
+ + " \"create service user test-user2\n"
+ + " set ACL for test-user2\n"
+ + " allow jcr:read on /conf\n"
+ + " end\",\\\n"
+ + " \"create path /test\n"
+ + " set properties on /test\n"
+ + " set testprop to \\\"one\\=two\\\"\n"
+ + " end\"\\\n"
+ + "]";
+
@Test
public void testComments() throws IOException
{
@@ -58,6 +89,15 @@ public class ConfigurationHandlerTest {
Assert.assertEquals(VAL_2, dict.get(PAR_2).toString());
}
+ @Test
+ public void testMultiLineConfig() throws IOException
+ {
+ @SuppressWarnings("unchecked")
+ final Dictionary<String, Object> dict = ConfigurationHandler.read(new ByteArrayInputStream(MULTI_LINE_CONFIG.getBytes("UTF-8")));
+ final String[] scripts = (String[]) dict.get("scripts");
+ Assert.assertNotNull(scripts);
+ Assert.assertEquals(3, scripts.length);
+ }
@Test
public void test_writeArray() throws IOException {