Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the implementation of golang's http.Dir for queue.createAbs()
- Loading branch information
1 parent
073387a
commit 65108ec
Showing
4 changed files
with
104 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package queue | ||
|
||
import ( | ||
"errors" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// Based on https://github.com/golang/go/blob/98842cabb6133ab7b8f2b323754a48085eed82f3/src/net/http/fs.go#L26-L50 | ||
// This code's license is https://github.com/golang/go/blob/98842cabb6133ab7b8f2b323754a48085eed82f3/LICENSE. | ||
func createAbs(root, name string) (p string, err error) { | ||
if root == "" || name == "" { | ||
return "", errors.New("all arguments must not be empty") | ||
} | ||
|
||
if filepath.Separator != '/' && strings.ContainsRune(name, filepath.Separator) || | ||
strings.Contains(name, "\x00") { | ||
return "", errors.New("invalid character in file path") | ||
} | ||
|
||
f := filepath.Join(filepath.FromSlash(path.Clean("/"+root)), filepath.FromSlash(path.Clean("/"+name))) | ||
if f == "/" { | ||
return "", errors.New("the result is `/`") | ||
} | ||
|
||
return f, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters