skip empty lines to avoid issue of #630 (#631)

* skip empty lines to avoid issue of #630

* add tests on empty lines and comms
This commit is contained in:
Thibault "bui" Koechlin 2021-02-25 09:57:24 +01:00 committed by GitHub
parent da84805f5f
commit a3d00fe130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -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()))

View file

@ -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",

View file

@ -0,0 +1,12 @@
foo
#toto
bar
baz