diff options
| author | Loyalsoldier <[email protected]> | 2024-08-11 04:54:27 +0800 |
|---|---|---|
| committer | Loyalsoldier <[email protected]> | 2024-08-11 04:54:27 +0800 |
| commit | 87dcc81c764c3c28fea6772df4b1352a6a3f89fe (patch) | |
| tree | 36085a74473ab5f3548c153261194a3f9d640e30 /plugin | |
| parent | 617ef1ea73b058290a0b0b7ff471fbd6ef381dbd (diff) | |
Fix: walk logic of local file
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/singbox/srs_in.go | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/plugin/singbox/srs_in.go b/plugin/singbox/srs_in.go index 44812cb8..8b664ce2 100644 --- a/plugin/singbox/srs_in.go +++ b/plugin/singbox/srs_in.go @@ -155,21 +155,28 @@ func (s *srsIn) walkDir(dir string, entries map[string]*lib.Entry) error { } func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error { + entryName := "" name = strings.TrimSpace(name) - var filename string if name != "" { - filename = name + entryName = name } else { - filename = filepath.Base(path) - } + entryName = filepath.Base(path) + + // check filename + if !regexp.MustCompile(`^[a-zA-Z0-9_.\-]+$`).MatchString(entryName) { + return fmt.Errorf("filename %s cannot be entry name, please remove special characters in it", entryName) + } - // check filename - if !regexp.MustCompile(`^[a-zA-Z0-9_.\-]+$`).MatchString(filename) { - return fmt.Errorf("filename %s cannot be entry name, please remove special characters in it", filename) + // remove file extension but not hidden files of which filename starts with "." + dotIndex := strings.LastIndex(entryName, ".") + if dotIndex > 0 { + entryName = entryName[:dotIndex] + } } - dotIndex := strings.LastIndex(filename, ".") - if dotIndex > 0 { - filename = filename[:dotIndex] + + entryName = strings.ToUpper(entryName) + if _, found := entries[entryName]; found { + return fmt.Errorf("found duplicated list %s", entryName) } file, err := os.Open(path) @@ -178,7 +185,7 @@ func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) } defer file.Close() - if err := s.generateEntries(filename, file, entries); err != nil { + if err := s.generateEntries(entryName, file, entries); err != nil { return err } @@ -204,6 +211,7 @@ func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) } func (s *srsIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error { + name = strings.ToUpper(name) entry, found := entries[name] if !found { entry = lib.NewEntry(name) |
