From c2d1f713059f8483ed4ff76242d666bbc61123b3 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 14 Apr 2023 19:06:25 +0800 Subject: [PATCH] fix: ruleProvider panic --- rules/provider/provider.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rules/provider/provider.go b/rules/provider/provider.go index a4271655..65d21d2f 100644 --- a/rules/provider/provider.go +++ b/rules/provider/provider.go @@ -187,6 +187,9 @@ func rulesParse(buf []byte, strategy ruleStrategy, format P.RuleFormat) (any, er firstLineLength = -1 // don't return ErrNoPayload when read last line str = string(line) str = strings.TrimSpace(str) + if len(str) == 0 { + continue + } if str[0] == '#' { // comment continue } @@ -194,7 +197,11 @@ func rulesParse(buf []byte, strategy ruleStrategy, format P.RuleFormat) (any, er continue } case P.YamlRule: - if bytes.TrimSpace(line)[0] == '#' { // comment + trimLine := bytes.TrimSpace(line) + if len(trimLine) == 0 { + continue + } + if trimLine[0] == '#' { // comment continue } firstLineBuffer.Write(line)