fix: refine regex patterns for server directives (#1384)

Updated regular expressions to handle optional whitespace and comments.
This commit is contained in:
LogicDX342
2025-10-07 21:55:35 -04:00
committed by GitHub
parent 49623c21c9
commit dc522dea6d

View File

@@ -48,9 +48,9 @@ func scanForSite(configPath string, content []byte) error {
}
// Regular expressions for server_name and listen directives
serverNameRegex := regexp.MustCompile(`(?m)server_name\s+([^;]+);`)
listenRegex := regexp.MustCompile(`(?m)listen\s+([^;]+);`)
returnRegex := regexp.MustCompile(`(?m)return\s+30[1-8]\s+https://`)
serverNameRegex := regexp.MustCompile(`(?m)^[ \t]*server_name\s+([^;#]+);`)
listenRegex := regexp.MustCompile(`(?m)^[ \t]*listen\s+([^;#]+);`)
returnRegex := regexp.MustCompile(`(?m)^[ \t]*return\s+30[1-8]\s+https://[^\s;#]+`)
// Find server blocks
serverBlockRegex := regexp.MustCompile(`(?ms)server\s*\{[^\{]*((.*?\{.*?\})*?[^\}]*)\}`)