lib/fs: Improve root check (#6033)
The root check would allow things like c:\foobar\baz if the root was c:\foo, because string wise that's a prefix. Now it doesn't.
This commit is contained in:
committed by
Audrius Butkevicius
parent
fd2e91c82d
commit
52d80d8144
@@ -62,6 +62,10 @@ func (f *BasicFilesystem) Roots() ([]string, error) {
|
||||
// pathseparator.
|
||||
func (f *BasicFilesystem) unrootedChecked(absPath string, roots []string) (string, *ErrWatchEventOutsideRoot) {
|
||||
for _, root := range roots {
|
||||
// Make sure the root ends with precisely one path separator, to
|
||||
// ease prefix comparisons.
|
||||
root := strings.TrimRight(root, string(PathSeparator)) + string(PathSeparator)
|
||||
|
||||
if absPath+string(PathSeparator) == root {
|
||||
return ".", nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user