Skip to content

Commit

Permalink
FELIX-6042 Lists are not recognized as typed properties
Browse files Browse the repository at this point in the history
Patch from Christoph Fiehe applied with many thanks!
This closes #176


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1852591 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bosschaert committed Jan 31, 2019
1 parent ddc6f23 commit 1184d28
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ public boolean nextProperty() throws IOException
String[] property = parseProperty(line);
boolean typed = false;
if (maybeTyped && property[1].length() >= 2) {
typed = property[1].matches("\\s*[TILFDXSCBilfdxscb]?(\\[[\\S\\s]*\\]|\\{[\\S\\s]*\\}|\"[\\S\\s]*\")\\s*");
typed = property[1].matches("\\s*[TILFDXSCBilfdxscb]?(\\[[\\S\\s]*\\]|\\([\\S\\s]*\\)|\\{[\\S\\s]*\\}|\"[\\S\\s]*\")\\s*");
}
if (this.typed == null) {
this.typed = typed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -343,9 +342,9 @@ public void testUpdate() throws Exception {

public void testSubstitution() throws IOException
{
String str = "port = 4141\n" +
"host = localhost\n" +
"url = https://${host}:${port}/service\n";
String str = "port = 4141" + LINE_SEPARATOR +
"host = localhost" + LINE_SEPARATOR +
"url = https://${host}:${port}/service" + LINE_SEPARATOR;
Properties properties = new Properties();
properties.load(new StringReader(str));
properties.put("url", "https://localhost:4141/service");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/
public class TypedPropertiesTest extends TestCase {

private final static String LINE_SEPARATOR = System.getProperty("line.separator");
private final static String TEST_PROPERTIES_FILE = "test.properties";
private final static String TEST_TYPED_PROPERTIES_FILE = "typed.properties";

Expand Down Expand Up @@ -94,14 +95,14 @@ public void testLoadTypedProps3() throws IOException
public void testWriteTypedPropsFloat() throws IOException
{
TypedProperties properties = new TypedProperties();
properties.load(new StringReader("key = F\"1137191584\"\n"));
properties.load(new StringReader("key = F\"1137191584\"" + LINE_SEPARATOR));
assertEquals(400.333f, properties.get("key"));
}

public void testReadStringWithEqual() throws IOException
{
TypedProperties properties = new TypedProperties();
properties.load(new StringReader("key = \"foo=bar\"\n"));
properties.load(new StringReader("key = \"foo=bar\"" + LINE_SEPARATOR));
assertEquals("foo=bar", properties.get("key"));
}

Expand All @@ -111,17 +112,48 @@ public void testWriteTypedPropsFloat2() throws IOException
properties.put("key", 400.333f);
StringWriter sw = new StringWriter();
properties.save(sw);
assertEquals("key = F\"400.333\"\n", sw.toString());
assertEquals("key = F\"400.333\"" + LINE_SEPARATOR, sw.toString());
properties = new TypedProperties();
properties.load(new StringReader(sw.toString()));
assertEquals(400.333f, properties.get("key"));
}

public void testWriteTypedPropsIntegerList() throws IOException
{
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
TypedProperties properties = new TypedProperties();
properties.put("key", list);
StringWriter sw = new StringWriter();
properties.save(sw);
String str = "key = I( \\\r\n \"1\", \\\r\n \"2\", \\\r\n \"3\", \\\r\n)" + LINE_SEPARATOR;
assertEquals(str, sw.toString());
properties = new TypedProperties();
properties.load(new StringReader(sw.toString()));
assertEquals(list, properties.get("key"));
}

public void testWriteTypedPropsFloatArray() throws IOException
{
Float[] array = new Float[] { 1.0f, 2.0f, 3.0f };
TypedProperties properties = new TypedProperties();
properties.put("key", array);
StringWriter sw = new StringWriter();
properties.save(sw);
String str = "key = F[ \\\r\n \"1.0\", \\\r\n \"2.0\", \\\r\n \"3.0\", \\\r\n ]" + LINE_SEPARATOR;
assertEquals(str, sw.toString());
properties = new TypedProperties();
properties.load(new StringReader(sw.toString()));
assertTrue(Arrays.equals(array, (Object[]) properties.get("key")));
}

public void testSubstitution() throws IOException
{
String str = "port = 4141\n" +
"host = localhost\n" +
"url = https://${host}:${port}/service\n";
String str = "port = 4141" + LINE_SEPARATOR +
"host = localhost" + LINE_SEPARATOR +
"url = https://${host}:${port}/service" + LINE_SEPARATOR;
TypedProperties properties = new TypedProperties();
properties.load(new StringReader(str));
properties.put("url", "https://localhost:4141/service");
Expand All @@ -137,7 +169,7 @@ public void testWriteTypedPropsStringWithSpaces() throws IOException
properties.put("key", "s 1");
StringWriter sw = new StringWriter();
properties.save(sw);
assertEquals("key = \"s 1\"\n", sw.toString());
assertEquals("key = \"s 1\"" + LINE_SEPARATOR, sw.toString());
}

}

0 comments on commit 1184d28

Please sign in to comment.