From 87840e0023f7adfb7ff928a8a5057932ea9aeab9 Mon Sep 17 00:00:00 2001 From: Marco Elver Date: Mon, 26 Sep 2022 15:41:28 +0200 Subject: pkg/config: fix comments stripping The comment-stripping regex doesn't work for multi-line comments, because the regex looks for a substring that both starts _and_ ends with a newline character. Since a single newline cannot be used into multiple matches, only the first comment line is found and later lines are not removed resulting in a parsing error. Fix it by looking for substrings _until_ a newline. --- pkg/config/config.go | 2 +- pkg/mgrconfig/testdata/gce1.cfg | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg') diff --git a/pkg/config/config.go b/pkg/config/config.go index 9ff25ecd7..8eb43fa58 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -26,7 +26,7 @@ func LoadFile(filename string, cfg interface{}) error { func LoadData(data []byte, cfg interface{}) error { // Remove comment lines starting with #. - data = regexp.MustCompile(`(^|\n)\s*#.*?\n`).ReplaceAll(data, nil) + data = regexp.MustCompile(`(^|\n)\s*#[^\n]*`).ReplaceAll(data, nil) dec := json.NewDecoder(bytes.NewReader(data)) dec.DisallowUnknownFields() if err := dec.Decode(cfg); err != nil { diff --git a/pkg/mgrconfig/testdata/gce1.cfg b/pkg/mgrconfig/testdata/gce1.cfg index 63320cd93..7f9d95c5d 100644 --- a/pkg/mgrconfig/testdata/gce1.cfg +++ b/pkg/mgrconfig/testdata/gce1.cfg @@ -3,6 +3,9 @@ # This is a test comment in the config. "name": "windows-gce", "target": "windows/amd64", + # This is a multi-line + # test comment in + # the config. "http": ":10000", "workdir": "/workdir", "syzkaller": "./testdata/syzkaller", -- cgit mrf-deployment