Skip to content

Commit

Permalink
Fix panic in toupper
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniomika committed Nov 11, 2023
1 parent ccc0df5 commit 4d12bdf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion filehandlers/imgs/img.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (h *UploadImgHandler) metaImg(data *PostMetaData) error {

img, err := shared.GetImageForOptimization(tee, data.MimeType)
finalName := shared.SanitizeFileExt(data.Filename)
if errors.Is(err, shared.AlreadyWebPError) {
if errors.Is(err, shared.ErrAlreadyWebPError) {
h.Cfg.Logger.Infof("(%s) is already webp, skipping encoding", data.Filename)
finalName = fmt.Sprintf("%s.webp", finalName)
webpReader = tee
Expand Down
6 changes: 3 additions & 3 deletions shared/img.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type Ratio struct {
Height int
}

var AlreadyWebPError = errors.New("image is already webp")
var IsSvgError = errors.New("image is an svg")
var ErrAlreadyWebPError = errors.New("image is already webp")
var ErrIsSvgError = errors.New("image is an svg")

func GetImageForOptimization(r io.Reader, mimeType string) (image.Image, error) {
switch mimeType {
Expand All @@ -54,7 +54,7 @@ func GetImageForOptimization(r io.Reader, mimeType string) (image.Image, error)
case "image/gif":
return gif.Decode(r)
case "image/webp":
return nil, AlreadyWebPError
return nil, ErrAlreadyWebPError
}

return nil, fmt.Errorf("(%s) not supported for optimization", mimeType)
Expand Down
6 changes: 5 additions & 1 deletion shared/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ func FilenameToTitle(filename string, title string) string {

func ToUpper(str string) string {
pre := fnameRe.ReplaceAllString(str, " ")

r := []rune(pre)
r[0] = unicode.ToUpper(r[0])
if len(r) > 0 {
r[0] = unicode.ToUpper(r[0])
}

return string(r)
}

Expand Down

0 comments on commit 4d12bdf

Please sign in to comment.