Skip to content

Commit dcaac53

Browse files
authored
Merge pull request #1201 from wakatime/bugfix/windows-split-drive
Fix panic for splitDrive
2 parents d3fa8b8 + 1279c08 commit dcaac53

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pkg/windows/windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func parseNetUseColumns(line string) (netUseColumns, error) {
259259

260260
// splitDrive splits a filepath into the drive letter and the path.
261261
func splitDrive(fp string) (string, string) {
262-
if fp[1:2] != ":" || !unicode.IsLetter(rune(fp[0])) {
262+
if len(fp) < 2 || fp[1:2] != ":" || !unicode.IsLetter(rune(fp[0])) {
263263
return "", fp
264264
}
265265

pkg/windows/windows_internal_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ func TestSplitDrive(t *testing.T) {
182182
ExpectedDriveLetter: ``,
183183
ExpectedPath: `_:\\remotepc\share`,
184184
},
185+
"one character drive": {
186+
Filepath: `A`,
187+
ExpectedDriveLetter: "",
188+
ExpectedPath: `A`,
189+
},
185190
}
186191

187192
for name, test := range tests {

0 commit comments

Comments
 (0)