diff --git a/build.gradle b/build.gradle index 9ca3a0e..fe0cdd2 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'it.fulminazzo' -version = '1.5.2' +version = '1.5.3' repositories { mavenCentral() diff --git a/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java b/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java index 932565f..1eb2b4f 100644 --- a/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java +++ b/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java @@ -966,9 +966,9 @@ default String getNameFromPath(@NotNull String path) { */ default @NotNull List parsePath(@NotNull String path) { List list = new ArrayList<>(); - for (String p : path.split("\\.")) - if (p.trim().isEmpty()) return list; - else list.add(p); + Matcher matcher = Pattern.compile("((?:\\\\\\.|[^.])+)(?:\\.|$)").matcher(path); + while (matcher.find()) + list.add(matcher.group(1)); return list; } @@ -1077,7 +1077,8 @@ default void print() { LinkedHashMap treeMap = new LinkedHashMap<>(); if (map == null) return treeMap; map.forEach((k, v) -> { - if (v instanceof Map) treeMap.put(k.toString(), new ConfigurationSection(parent, k.toString(), (Map) v)); + final String key = k.toString().replace(".", "\\."); + if (v instanceof Map) treeMap.put(key, new ConfigurationSection(parent, key, (Map) v)); else { if (v instanceof List) { List list = (List) v; @@ -1087,7 +1088,7 @@ default void print() { list.set(i, new ConfigurationSection(parent, String.valueOf(i), (Map) v2)); } } - treeMap.put(k.toString(), v); + treeMap.put(key, v); } }); return treeMap; @@ -1103,7 +1104,8 @@ default void print() { if (config == null) return null; LinkedHashMap treeMap = new LinkedHashMap<>(); Map map = config.toMap(); - map.forEach((String k, @Nullable Object v) -> { + map.forEach((k, v) -> { + k = k.replace("\\.", "."); if (v instanceof IConfiguration) v = configToGeneralMap((IConfiguration) v); else if (v instanceof List) { List list = new LinkedList<>((Collection) v); diff --git a/src/test/java/it/fulminazzo/yamlparser/configuration/FileConfigurationTest.java b/src/test/java/it/fulminazzo/yamlparser/configuration/FileConfigurationTest.java index d7cd252..7c6bf01 100644 --- a/src/test/java/it/fulminazzo/yamlparser/configuration/FileConfigurationTest.java +++ b/src/test/java/it/fulminazzo/yamlparser/configuration/FileConfigurationTest.java @@ -242,6 +242,17 @@ void testRemoveParsersFromPackage() { assertEquals(new LinkedList<>(), FileConfiguration.getParsers()); } + @Test + void testDottedValues() throws IOException { + final File parent = new File(filePath).getParentFile(); + final File file = new File(parent, "test-dot.yml"); + final String fileContents = FileUtils.readFileToString(file) + "\n"; + FileConfiguration config = new FileConfiguration(file); + assertEquals(1, config.getInteger("dotted\\.value")); + config.save(); + assertEquals(fileContents, FileUtils.readFileToString(file)); + } + @Test void listShouldBeParsed() { ConfigurationSection s1; diff --git a/src/test/resources/test-dot.yml b/src/test/resources/test-dot.yml new file mode 100644 index 0000000..ac8ad5c --- /dev/null +++ b/src/test/resources/test-dot.yml @@ -0,0 +1 @@ +dotted.value: 1 \ No newline at end of file