mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-22 13:50:40 +07:00
feat: subscription supports file://
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user