mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
feat: 优化 Nginx 版本解析逻辑,添加正则表达式匹配,更新测试用例以验证新逻辑
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -300,19 +301,15 @@ func detectVersion(ctx context.Context, options ExecutorOptions, runner CommandR
|
||||
}
|
||||
|
||||
func parseNginxVersion(output string) string {
|
||||
start := strings.Index(output, "nginx/")
|
||||
if start < 0 {
|
||||
matches := nginxVersionPattern.FindStringSubmatch(output)
|
||||
if len(matches) != 2 {
|
||||
return ""
|
||||
}
|
||||
version := output[start+len("nginx/"):]
|
||||
for i, r := range version {
|
||||
if r == ' ' || r == '\n' || r == '\r' || r == '\t' {
|
||||
return version[:i]
|
||||
}
|
||||
}
|
||||
return version
|
||||
return matches[1]
|
||||
}
|
||||
|
||||
var nginxVersionPattern = regexp.MustCompile(`(?im)nginx version:\s*nginx/([^\s]+)`)
|
||||
|
||||
type backupState struct {
|
||||
RouteExisted bool
|
||||
RouteData []byte
|
||||
|
||||
Reference in New Issue
Block a user