From 816f1d61234a3255dd47112811f1ffff71a14072 Mon Sep 17 00:00:00 2001 From: Meo597 <197331664+Meo597@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:52:06 +0800 Subject: [PATCH] file ext ignore case --- common/lua/program_test.go | 11 ++++++++++- common/platform/filesystem/file.go | 3 ++- main/commands/all/lua/sign.go | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/lua/program_test.go b/common/lua/program_test.go index 1341e0d94..67ce8153b 100644 --- a/common/lua/program_test.go +++ b/common/lua/program_test.go @@ -187,11 +187,20 @@ func TestCompileInlineDiagnostics(t *testing.T) { */ func TestCompileFileExtension(t *testing.T) { - for _, name := range []string{"script", "script.dat", "script.lua.txt", "script.LUA"} { + for _, name := range []string{"script", "script.dat", "script.lua.txt"} { if program, err := Compile(name); program != nil || err == nil || !strings.Contains(err.Error(), "Lua file extension must be .lua") { t.Fatalf("Compile(%q) = %v, %v; want nil program and .lua extension error", name, program, err) } } + for _, name := range []string{"script.lua", "script.LUA", "script.Lua", "script.lUa"} { + path := filepath.Join(t.TempDir(), name) + if err := os.WriteFile(path, []byte("value = 42"), 0o600); err != nil { + t.Fatal(err) + } + if program, err := Compile(path); program == nil || err != nil { + t.Fatalf("Compile(%q) = %v, %v; want successful compilation", path, program, err) + } + } } func TestCompileRejectsReadFailure(t *testing.T) { diff --git a/common/platform/filesystem/file.go b/common/platform/filesystem/file.go index 4de0291da..55c0e9365 100644 --- a/common/platform/filesystem/file.go +++ b/common/platform/filesystem/file.go @@ -5,6 +5,7 @@ import ( "io" "os" "path/filepath" + "strings" "github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/platform" @@ -69,7 +70,7 @@ func ReadCert(file string) ([]byte, error) { // ResolveLuaFile finds a local .lua script and returns its absolute path. // Relative paths: XRAY_LOCATION_CONFDIR > XRAY_LOCATION_CONFIG > working dir > executable dir. func ResolveLuaFile(path string) (string, error) { - if filepath.Ext(path) != ".lua" { + if !strings.EqualFold(filepath.Ext(path), ".lua") { return "", errors.New("Lua file extension must be .lua") } if filepath.IsAbs(path) { diff --git a/main/commands/all/lua/sign.go b/main/commands/all/lua/sign.go index cf23176f3..3ef27e190 100644 --- a/main/commands/all/lua/sign.go +++ b/main/commands/all/lua/sign.go @@ -3,6 +3,7 @@ package lua import ( "os" "path/filepath" + "strings" xlua "github.com/xtls/xray-core/common/lua" "github.com/xtls/xray-core/main/commands/base" @@ -32,7 +33,7 @@ func executeSign(cmd *base.Command, args []string) { cmd.Usage() } - if filepath.Ext(args[0]) != ".lua" { + if !strings.EqualFold(filepath.Ext(args[0]), ".lua") { base.Fatalf("Lua file extension must be .lua") } info, err := os.Stat(args[0])