escape double quotes
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Harvey Tindall 2022-01-27 17:59:32 +00:00
parent 39f84a94ac
commit 485ec0ec0a
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

32
main.go
View File

@ -150,6 +150,10 @@ func secondsToString(seconds int) string {
// JSON returns json for waybar to consume. // JSON returns json for waybar to consume.
func playerJSON(p *player) string { func playerJSON(p *player) string {
artist := strings.ReplaceAll(p.Artist, "\"", "\\\"")
album := strings.ReplaceAll(p.Album, "\"", "\\\"")
title := strings.ReplaceAll(p.Title, "\"", "\\\"")
name := strings.ReplaceAll(p.Name, "\"", "\\\"")
symbol := PLAY symbol := PLAY
out := "{\"class\": \"" out := "{\"class\": \""
if p.Playing { if p.Playing {
@ -177,24 +181,24 @@ func playerJSON(p *player) string {
case "SYMBOL": case "SYMBOL":
items = append(items, symbol) items = append(items, symbol)
case "ARTIST": case "ARTIST":
if p.Artist != "" { if artist != "" {
items = append(items, p.Artist) items = append(items, artist)
} }
case "ALBUM": case "ALBUM":
if p.Album != "" { if album != "" {
items = append(items, p.Album) items = append(items, album)
} }
case "TITLE": case "TITLE":
if p.Title != "" { if title != "" {
items = append(items, p.Title) items = append(items, title)
} }
case "POSITION": case "POSITION":
if pos != "" && SHOW_POS { if pos != "" && SHOW_POS {
items = append(items, pos) items = append(items, pos)
} }
case "PLAYER": case "PLAYER":
if p.Name != "" { if name != "" {
items = append(items, p.Name) items = append(items, name)
} }
} }
} }
@ -214,14 +218,14 @@ func playerJSON(p *player) string {
text += v + right text += v + right
} }
out += "\",\"text\":\"" + text + "\"," out += "\",\"text\":\"" + text + "\","
out += "\"tooltip\":\"" + strings.ReplaceAll(p.Title, "&", "&") + "\\n" out += "\"tooltip\":\"" + strings.ReplaceAll(title, "&", "&") + "\\n"
if p.Artist != "" { if artist != "" {
out += "by " + strings.ReplaceAll(p.Artist, "&", "&") + "\\n" out += "by " + strings.ReplaceAll(artist, "&", "&") + "\\n"
} }
if p.Album != "" { if album != "" {
out += "from " + strings.ReplaceAll(p.Album, "&", "&") + "\\n" out += "from " + strings.ReplaceAll(album, "&", "&") + "\\n"
} }
out += "(" + p.Name + ")\"}" out += "(" + name + ")\"}"
return out return out
// return fmt.Sprintf("{\"class\":\"%s\",\"text\":\"%s\",\"tooltip\":\"%s\"}", data["class"], data["text"], data["tooltip"]) // return fmt.Sprintf("{\"class\":\"%s\",\"text\":\"%s\",\"tooltip\":\"%s\"}", data["class"], data["text"], data["tooltip"])
// out, err := json.Marshal(data) // out, err := json.Marshal(data)