Skip to content

Commit

Permalink
clean extra slashes from path
Browse files Browse the repository at this point in the history
  • Loading branch information
kd7lxl committed Sep 26, 2024
1 parent fe02b57 commit bfe9414
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fsnotify/filewatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"net/url"
"os"
"path"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -116,6 +117,7 @@ func (s *Strategy) setVal(pth string, val string) {

// Watch implements the hotload.Strategy interface.
func (s *Strategy) Watch(ctx context.Context, pth string, options url.Values) (value string, values <-chan string, err error) {
pth = path.Clean(pth)
s.mu.Lock()
defer s.mu.Unlock()
// if this is the first time this strategy is called, initialize ourselves
Expand Down
20 changes: 20 additions & 0 deletions fsnotify/filewatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ var _ = Describe("FileWatcher", func() {
os.Remove(args.pth)
},
}),
Entry("extra slash in path", test{
setup: func(args *args) {
f, _ := os.CreateTemp("", "unittest_")
f.Write([]byte("a"))
args.pth = "/" + f.Name()
f.Close()
},
wantErr: false,
post: func(args *args, value string, values <-chan string) error {
if value != "a" {
return fmt.Errorf("expected 'a' got %v", value)
}
os.WriteFile(args.pth, []byte("b"), 0660)
assertStringFromChannel("wating for update b", "b", values)
return nil
},
tearDown: func(args *args) {
os.Remove(args.pth)
},
}),
Entry("a, rm a, create b", test{
setup: func(args *args) {
f, _ := os.CreateTemp("", "unittest_")
Expand Down

0 comments on commit bfe9414

Please sign in to comment.