Skip to content

Commit

Permalink
Windows has prefix fix (#4156)
Browse files Browse the repository at this point in the history
* Add unit test to catch error

* the fix
  • Loading branch information
leehinman authored Jan 29, 2024
1 parent c5ecc02 commit 9c40d66
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/pkg/agent/application/paths/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestHasPrefixUnix(t *testing.T) {
"trailing slash": {path: "/a/b/", prefix: "/a", want: true},
"no path": {path: "", prefix: "/a", want: false},
"no prefix": {path: "/a/b", prefix: "", want: false},
"middle differ": {path: "/a/b/c", prefix: "/a/d/c", want: false},
}

for name, tc := range tests {
Expand Down Expand Up @@ -79,6 +80,7 @@ func TestHasPrefixWindows(t *testing.T) {
"no path": {path: "", prefix: "c:\\a", want: false},
"no prefix": {path: "c:\\a\\b", prefix: "", want: false},
"case insensitive": {path: "C:\\A\\B", prefix: "c:\\a", want: true},
"middle differ": {path: "c:\\a\\b\\c", prefix: "c:\\a\\d\\c", want: false},
}

for name, tc := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/paths/paths_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func HasPrefix(path string, prefix string) bool {
}

for i := 0; i < len(prefixParts); i++ {
if !strings.EqualFold(prefixParts[0], pathParts[0]) {
if !strings.EqualFold(prefixParts[i], pathParts[i]) {
return false
}
}
Expand Down

0 comments on commit 9c40d66

Please sign in to comment.