Skip to content

Commit 2ce5fe9

Browse files
committed
Handle illegal characters in thumbnails URL
1 parent e789df1 commit 2ce5fe9

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

menu/thumbnail.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"os"
88
"os/user"
9+
"strings"
910

1011
"github.com/libretro/ludo/video"
1112
)
@@ -42,11 +43,27 @@ func downloadThumbnail(list *entry, i int, url, folderPath, path string) {
4243
io.Copy(out, resp.Body)
4344
}
4445

46+
// Scrub characters that are not cross-platform and/or violate the
47+
// No-Intro filename standard.
48+
func scrubIllegalChars(str string) string {
49+
str = strings.Replace(str, "&", "_", -1)
50+
str = strings.Replace(str, "*", "_", -1)
51+
str = strings.Replace(str, "/", "_", -1)
52+
str = strings.Replace(str, ":", "_", -1)
53+
str = strings.Replace(str, "`", "_", -1)
54+
str = strings.Replace(str, "<", "_", -1)
55+
str = strings.Replace(str, ">", "_", -1)
56+
str = strings.Replace(str, "?", "_", -1)
57+
str = strings.Replace(str, "|", "_", -1)
58+
return str
59+
}
60+
4561
func drawThumbnail(list *entry, i int, system, gameName string, x, y, w, h, scale float32) {
4662
usr, _ := user.Current()
4763
folderPath := usr.HomeDir + "/.ludo/thumbnails/" + system + "/Named_Snaps/"
4864
path := folderPath + gameName + ".png"
49-
url := "http://thumbnails.libretro.com/" + system + "/Named_Snaps/" + gameName + ".png"
65+
legalName := scrubIllegalChars(gameName)
66+
url := "http://thumbnails.libretro.com/" + system + "/Named_Snaps/" + legalName + ".png"
5067

5168
if list.children[i].thumbnail == 0 || list.children[i].thumbnail == menu.icons["img-dl"] {
5269
if _, err := os.Stat(path); !os.IsNotExist(err) {

0 commit comments

Comments
 (0)