mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-17 23:57:15 +00:00
fix(panel): recognize this fork's -awg.N tags in version comparison
internal/config/version was never bumped past 3.5.0 when v3.5.0-awg.1 was tagged, so a freshly-updated panel kept reporting its own version as the plain upstream base. On top of that, parseVersionParts (Go and its TypeScript mirror) required exactly 3 dot-separated numeric parts, so it rejected the -awg.N suffix entirely and fell back to a raw string inequality that reports "update available" any time the strings merely differ -- which they always do here, even when already on the latest tag. Bump the embedded version to 3.5.0-awg.1 and extend both parsers to treat "-awg.N" as an optional 4th, lower-priority component (defaulting to 0 for a plain tag), so e.g. 3.5.0-awg.2 > 3.5.0-awg.1 > 3.5.0 and a matching tag compares equal instead of always looking outdated. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -529,13 +529,22 @@ func compareVersionStrings(a string, b string) (int, bool) {
|
||||
return 0, true
|
||||
}
|
||||
|
||||
func parseVersionParts(version string) ([3]int, bool) {
|
||||
var result [3]int
|
||||
parts := strings.Split(normalizeVersionTag(version), ".")
|
||||
if len(parts) != 3 {
|
||||
// versionPartsPattern matches a plain "X.Y.Z" tag as well as this fork's own
|
||||
// "X.Y.Z-awg.N" release tags (see internal/config/version). The awg build
|
||||
// number is treated as a 4th, lower-priority component that defaults to 0 for
|
||||
// a plain upstream-style tag, so e.g. "3.5.0-awg.2" > "3.5.0-awg.1" > "3.5.0".
|
||||
var versionPartsPattern = regexp.MustCompile(`^v?(\d+)\.(\d+)\.(\d+)(?:-awg\.(\d+))?$`)
|
||||
|
||||
func parseVersionParts(version string) ([4]int, bool) {
|
||||
var result [4]int
|
||||
matches := versionPartsPattern.FindStringSubmatch(strings.TrimSpace(version))
|
||||
if matches == nil {
|
||||
return result, false
|
||||
}
|
||||
for i, part := range parts {
|
||||
for i, part := range matches[1:] {
|
||||
if part == "" {
|
||||
continue // awg build number omitted -- defaults to 0
|
||||
}
|
||||
n, err := strconv.Atoi(part)
|
||||
if err != nil {
|
||||
return result, false
|
||||
|
||||
@@ -42,6 +42,31 @@ func TestCompareVersionStringsRejectsUnexpectedFormats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestIsNewerVersionAwgSuffix covers this fork's own "-awg.N" release tags
|
||||
// (see internal/config/version), which must compare correctly against both
|
||||
// plain upstream-style tags and other awg builds of the same base version.
|
||||
func TestIsNewerVersionAwgSuffix(t *testing.T) {
|
||||
cases := []struct {
|
||||
latest string
|
||||
current string
|
||||
want bool
|
||||
}{
|
||||
{"v3.5.0-awg.1", "3.5.0-awg.1", false},
|
||||
{"v3.5.0-awg.2", "3.5.0-awg.1", true},
|
||||
{"v3.5.0-awg.1", "3.5.0-awg.2", false},
|
||||
{"v3.5.0-awg.1", "3.5.0", true},
|
||||
{"v3.5.0", "3.5.0-awg.1", false},
|
||||
{"v3.6.0", "3.5.0-awg.1", true},
|
||||
{"v3.5.0-awg.1", "3.6.0", false},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
if got := isNewerVersion(tc.latest, tc.current); got != tc.want {
|
||||
t.Fatalf("isNewerVersion(%q, %q) = %v, want %v", tc.latest, tc.current, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellQuote(t *testing.T) {
|
||||
if got := shellQuote("/usr/bin/curl"); got != "'/usr/bin/curl'" {
|
||||
t.Fatalf("unexpected quote result: %s", got)
|
||||
|
||||
Reference in New Issue
Block a user