feat: subscription supports file://

This commit is contained in:
mzz2017
2023-02-09 20:17:45 +08:00
parent 3060417be7
commit 8bb88ed20a
4 changed files with 73 additions and 8 deletions

View File

@ -11,6 +11,7 @@ import (
"encoding/hex"
"fmt"
"net/url"
"path/filepath"
"reflect"
"strconv"
"strings"
@ -307,3 +308,18 @@ func FuzzyDecode(to interface{}, val string) bool {
}
return true
}
func IsFileInSubDir(filePath string, dir string) (err error) {
fileDir := filepath.Dir(filePath)
if len(dir) == 0 {
return fmt.Errorf("bad dir: %v", dir)
}
rel, err := filepath.Rel(dir, fileDir)
if err != nil {
return err
}
if strings.HasPrefix(rel, "..") {
return fmt.Errorf("file is out of scope: %v", rel)
}
return nil
}