Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #55 from owulveryck/issue/filenameTooLong
Browse files Browse the repository at this point in the history
fix(addMedia): if filename is too long of invalid, use a custom filename
  • Loading branch information
owulveryck committed Oct 21, 2021
2 parents a12214f + c919cc7 commit 734ccbc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions epub.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package epub

import (
"fmt"
"io/fs"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -448,8 +449,9 @@ func addMedia(client *http.Client, source string, internalFilename string, media
if internalFilename == "" {
// If a filename isn't provided, use the filename from the source
internalFilename = filepath.Base(source)
// If that's already used, try to generate a unique filename
if _, ok := mediaMap[internalFilename]; ok {
_, ok := mediaMap[internalFilename]
// if filename is too long, invalid or already used, try to generate a unique filename
if len(internalFilename) > 255 || !fs.ValidPath(internalFilename) || ok {
internalFilename = fmt.Sprintf(
mediaFileFormat,
len(mediaMap)+1,
Expand Down

0 comments on commit 734ccbc

Please sign in to comment.