file ext ignore case

This commit is contained in:
Meo597
2026-10-26 21:52:06 +08:00
parent 75c08917e3
commit 816f1d6123
3 changed files with 14 additions and 3 deletions
+10 -1
View File
@@ -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) {
+2 -1
View File
@@ -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) {
+2 -1
View File
@@ -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])