From a3d00fe130729160cdec328f2dbc1da517539281 Mon Sep 17 00:00:00 2001 From: "Thibault \"bui\" Koechlin" Date: Thu, 25 Feb 2021 09:57:24 +0100 Subject: [PATCH] skip empty lines to avoid issue of #630 (#631) * skip empty lines to avoid issue of #630 * add tests on empty lines and comms --- pkg/exprhelpers/exprlib.go | 3 +++ pkg/exprhelpers/exprlib_test.go | 6 ++++++ pkg/exprhelpers/tests/test_empty_line.txt | 12 ++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 pkg/exprhelpers/tests/test_empty_line.txt diff --git a/pkg/exprhelpers/exprlib.go b/pkg/exprhelpers/exprlib.go index b158a269f86..cb468b2f003 100644 --- a/pkg/exprhelpers/exprlib.go +++ b/pkg/exprhelpers/exprlib.go @@ -73,6 +73,9 @@ func FileInit(fileFolder string, filename string, fileType string) error { if strings.HasPrefix(scanner.Text(), "#") { // allow comments continue } + if len(scanner.Text()) == 0 { //skip empty lines + continue + } switch fileType { case "regex", "regexp": dataFileRegex[filename] = append(dataFileRegex[filename], regexp.MustCompile(scanner.Text())) diff --git a/pkg/exprhelpers/exprlib_test.go b/pkg/exprhelpers/exprlib_test.go index 7bd317bbef4..9de65a23e73 100644 --- a/pkg/exprhelpers/exprlib_test.go +++ b/pkg/exprhelpers/exprlib_test.go @@ -178,6 +178,12 @@ func TestFileInit(t *testing.T) { types: "string", result: 3, }, + { + name: "file with type:string and empty lines + commentaries", + filename: "test_empty_line.txt", + types: "string", + result: 3, + }, { name: "file with type:re", filename: "test_data_re.txt", diff --git a/pkg/exprhelpers/tests/test_empty_line.txt b/pkg/exprhelpers/tests/test_empty_line.txt new file mode 100644 index 00000000000..ca09bd0bec5 --- /dev/null +++ b/pkg/exprhelpers/tests/test_empty_line.txt @@ -0,0 +1,12 @@ +foo + +#toto + + +bar + + + + + +baz