diff options
| author | Marco Elver <elver@google.com> | 2022-09-26 15:41:28 +0200 |
|---|---|---|
| committer | Marco Elver <me@marcoelver.com> | 2022-09-27 12:33:44 +0200 |
| commit | 87840e0023f7adfb7ff928a8a5057932ea9aeab9 (patch) | |
| tree | 266c5a18baf4ea1f0343ced35c6eed782b712dfa /pkg/config/config.go | |
| parent | 10323ddf71b1e5ea30453d7bf17f0815d9e0514a (diff) | |
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.
Diffstat (limited to 'pkg/config/config.go')
| -rw-r--r-- | pkg/config/config.go | 2 |
1 files changed, 1 insertions, 1 deletions
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 { |
