Skip to content

Commit

Permalink
Extract hasPermittedExtension function
Browse files Browse the repository at this point in the history
  • Loading branch information
hrs committed Jun 8, 2023
1 parent 0b4b3b6 commit 21e8fad
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion corpus/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (doc *Document) calcNorm() float64 {

func isTextFile(path string) bool {
// If the file's extension is explicitly permitted, just use that.
if permitted, _ := explicitlyPermittedExtensions[filepath.Ext(path)]; permitted {
if hasPermittedExtension(path) {
return true
}

Expand Down Expand Up @@ -169,3 +169,9 @@ func isTextFile(path string) bool {

return strings.HasPrefix(mimeType, "text/")
}

func hasPermittedExtension(path string) bool {
ext := strings.TrimPrefix(filepath.Ext(path), ".")
permitted, ok := explicitlyPermittedExtensions[ext]
return ok && permitted
}

0 comments on commit 21e8fad

Please sign in to comment.