Feat: check regexp before build (#3064)

Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
This commit is contained in:
风扇滑翔翼
2025-12-16 23:40:25 +08:00
committed by GitHub
parent cbe19f0562
commit 93bfcfd142

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
@@ -71,6 +72,11 @@ func (l *ParsedList) toProto() (*router.GeoSite, error) {
Attribute: entry.Attrs,
})
case "regexp":
// check regexp validity to avoid runtime error
_, err := regexp.Compile(entry.Value)
if err != nil {
return nil, fmt.Errorf("invalid regexp in list %s: %s", l.Name, entry.Value)
}
site.Domain = append(site.Domain, &router.Domain{
Type: router.Domain_Regex,
Value: entry.Value,