Skip to content

Commit

Permalink
Use prefix as-is, do not change to lower/upper case
Browse files Browse the repository at this point in the history
  • Loading branch information
leibowitz committed Dec 20, 2021
1 parent b94b5f5 commit e65279f
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions pypiisms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,22 @@ func handlePypiFileNames(key string) string {
func handlePypiListDir(fetcher FileFetcher, path string) ([]ListDirEntry, error) {
prefix := strings.TrimPrefix(path, "/") // remove initial /
prefix = strings.TrimSuffix(prefix, "/") // and last one
prefix = strings.Replace(prefix, "-", "_", -1)


if len(prefix) < 1 {
return nil, fmt.Errorf("expected a directory to list")
}

// case-insensitive search, search for X* + x*
lowerFiles, err := fetcher.ListDir(strings.ToLower(prefix))
if err != nil {
return lowerFiles, err
}
upperFiles, err := fetcher.ListDir(strings.ToUpper(prefix))
files, err := fetcher.ListDir(prefix)
if err != nil {
return upperFiles, err
return files, err
}

// now merge both and filter by normalized prefix comparison.
allFiles := append(lowerFiles, upperFiles...)
// now filter by normalized prefix comparison.
normalizedPrefix := normalizeFileName(prefix)
var results []ListDirEntry
for _, entry := range allFiles {
for _, entry := range files {
fileName := normalizeFileName(entry.Name)
if strings.HasPrefix(fileName, normalizedPrefix) {
results = append(results, entry)
Expand Down

0 comments on commit e65279f

Please sign in to comment.