From 0993b354e55133986d7bb0372ffe21d3a4b76c33 Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Fri, 3 Dec 2021 08:33:46 +0800 Subject: [PATCH] ConfigParser: do NOT override existing sections This commit support format as below: ``` [DNS] EQUAL,example.com [URL] PREFIX,https://example.com/a [URL] PREFIX,https://example.com/foo [URL] PREFIX,https://example.com/bar ``` It merges sections with the same section name. --- .../io/zhile/research/ja/netfilter/commons/ConfigParser.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java b/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java index 9ea4b3d..fdc6ff3 100644 --- a/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java +++ b/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java @@ -45,7 +45,10 @@ public class ConfigParser { } lastSection = section; - map.put(lastSection, new ArrayList<>()); + if (null == map.get(lastSection)) { + // do NOT override existing sections + map.put(lastSection, new ArrayList<>()); + } break; case '#': case ';':