Skip to content

Commit f9ecd96

Browse files
authored
Merge pull request #10 from citymapper/fixes
Ensure we have a prefix
2 parents 032b49c + 916f20d commit f9ecd96

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pypiisms.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

3-
import "strings"
3+
import (
4+
"fmt"
5+
"strings"
6+
)
47

58
func normalizeFileName(filePath string) string {
69
normalized := strings.Replace(strings.ToLower(filePath), "_", "-", -1)
@@ -21,10 +24,13 @@ func handlePypiFileNames(key string) string {
2124

2225
// handlePypiDirlist works around the fact that dirlistings are case insensitive so direct search for the path might fail
2326
func handlePypiListDir(fetcher FileFetcher, path string) ([]ListDirEntry, error) {
24-
2527
prefix := strings.TrimPrefix(path, "/") // remove initial /
2628
prefix = strings.TrimSuffix(prefix, "/") // and last one
2729

30+
if len(prefix) < 1 {
31+
return nil, fmt.Errorf("expected a directory to list")
32+
}
33+
2834
// case-insensitive search, search for X* + x*
2935
firstLetter := prefix[0:1]
3036
lowerFiles, err := fetcher.ListDir(strings.ToLower(firstLetter))

0 commit comments

Comments
 (0)