This commit is contained in:
@@ -23,7 +23,6 @@ var (
|
|||||||
errInvalidFilenameWindowsSpacePeriod = errors.New("name is invalid, must not end in space or period on Windows")
|
errInvalidFilenameWindowsSpacePeriod = errors.New("name is invalid, must not end in space or period on Windows")
|
||||||
errInvalidFilenameWindowsReservedName = errors.New("name is invalid, contains Windows reserved name (NUL, COM1, etc.)")
|
errInvalidFilenameWindowsReservedName = errors.New("name is invalid, contains Windows reserved name (NUL, COM1, etc.)")
|
||||||
errInvalidFilenameWindowsReservedChar = errors.New("name is invalid, contains Windows reserved character (?, *, etc.)")
|
errInvalidFilenameWindowsReservedChar = errors.New("name is invalid, contains Windows reserved character (?, *, etc.)")
|
||||||
errNotRelative = errors.New("not a relative path")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type OptionJunctionsAsDirs struct{}
|
type OptionJunctionsAsDirs struct{}
|
||||||
|
|||||||
@@ -249,6 +249,11 @@ func IsInternal(file string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
errPathInvalid = errors.New("path is invalid")
|
||||||
|
errPathTraversingUpwards = errors.New("relative path traversing upwards (starting with ..)")
|
||||||
|
)
|
||||||
|
|
||||||
// Canonicalize checks that the file path is valid and returns it in the "canonical" form:
|
// Canonicalize checks that the file path is valid and returns it in the "canonical" form:
|
||||||
// - /foo/bar -> foo/bar
|
// - /foo/bar -> foo/bar
|
||||||
// - / -> "."
|
// - / -> "."
|
||||||
@@ -259,7 +264,7 @@ func Canonicalize(file string) (string, error) {
|
|||||||
// The relative path may pretend to be an absolute path within
|
// The relative path may pretend to be an absolute path within
|
||||||
// the root, but the double path separator on Windows implies
|
// the root, but the double path separator on Windows implies
|
||||||
// something else and is out of spec.
|
// something else and is out of spec.
|
||||||
return "", errNotRelative
|
return "", errPathInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
// The relative path should be clean from internal dotdots and similar
|
// The relative path should be clean from internal dotdots and similar
|
||||||
@@ -268,10 +273,10 @@ func Canonicalize(file string) (string, error) {
|
|||||||
|
|
||||||
// It is not acceptable to attempt to traverse upwards.
|
// It is not acceptable to attempt to traverse upwards.
|
||||||
if file == ".." {
|
if file == ".." {
|
||||||
return "", errNotRelative
|
return "", errPathTraversingUpwards
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(file, ".."+pathSep) {
|
if strings.HasPrefix(file, ".."+pathSep) {
|
||||||
return "", errNotRelative
|
return "", errPathTraversingUpwards
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(file, pathSep) {
|
if strings.HasPrefix(file, pathSep) {
|
||||||
|
|||||||
Reference in New Issue
Block a user