Skip to content

Commit

Permalink
clean extra slashes from path (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel García <[email protected]>
  • Loading branch information
kd7lxl and daniel-garcia authored Sep 28, 2024
1 parent 3a92f6e commit 4609806
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 @@ -4,6 +4,7 @@ import (
"context"
"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 4609806

Please sign in to comment.