Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean extra slashes from path #33

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading