repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
4d12bdf
parent
ccc0df5
author
Antonio Mika
date
2023-11-11 20:44:44 +0000 UTC
Fix panic in toupper
3 files changed,  +9, -5
M filehandlers/imgs/img.go
+1, -1
1@@ -83,7 +83,7 @@ func (h *UploadImgHandler) metaImg(data *PostMetaData) error {
2 
3 	img, err := shared.GetImageForOptimization(tee, data.MimeType)
4 	finalName := shared.SanitizeFileExt(data.Filename)
5-	if errors.Is(err, shared.AlreadyWebPError) {
6+	if errors.Is(err, shared.ErrAlreadyWebPError) {
7 		h.Cfg.Logger.Infof("(%s) is already webp, skipping encoding", data.Filename)
8 		finalName = fmt.Sprintf("%s.webp", finalName)
9 		webpReader = tee
M shared/img.go
+3, -3
 1@@ -40,8 +40,8 @@ type Ratio struct {
 2 	Height int
 3 }
 4 
 5-var AlreadyWebPError = errors.New("image is already webp")
 6-var IsSvgError = errors.New("image is an svg")
 7+var ErrAlreadyWebPError = errors.New("image is already webp")
 8+var ErrIsSvgError = errors.New("image is an svg")
 9 
10 func GetImageForOptimization(r io.Reader, mimeType string) (image.Image, error) {
11 	switch mimeType {
12@@ -54,7 +54,7 @@ func GetImageForOptimization(r io.Reader, mimeType string) (image.Image, error)
13 	case "image/gif":
14 		return gif.Decode(r)
15 	case "image/webp":
16-		return nil, AlreadyWebPError
17+		return nil, ErrAlreadyWebPError
18 	}
19 
20 	return nil, fmt.Errorf("(%s) not supported for optimization", mimeType)
M shared/util.go
+5, -1
 1@@ -41,8 +41,12 @@ func FilenameToTitle(filename string, title string) string {
 2 
 3 func ToUpper(str string) string {
 4 	pre := fnameRe.ReplaceAllString(str, " ")
 5+
 6 	r := []rune(pre)
 7-	r[0] = unicode.ToUpper(r[0])
 8+	if len(r) > 0 {
 9+		r[0] = unicode.ToUpper(r[0])
10+	}
11+
12 	return string(r)
13 }
14