Skip to content

Commit

Permalink
skip empty lines to avoid issue of crowdsecurity#630 (crowdsecurity#631)
Browse files Browse the repository at this point in the history
* skip empty lines to avoid issue of crowdsecurity#630

* add tests on empty lines and comms
  • Loading branch information
buixor authored Feb 25, 2021
1 parent da84805 commit a3d00fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/exprhelpers/exprlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
6 changes: 6 additions & 0 deletions pkg/exprhelpers/exprlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions pkg/exprhelpers/tests/test_empty_line.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
foo

#toto


bar





baz

0 comments on commit a3d00fe

Please sign in to comment.