aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarvey Tindall <hrfee@protonmail.ch>2022-01-27 17:59:32 +0000
committerHarvey Tindall <hrfee@protonmail.ch>2022-01-27 18:00:49 +0000
commit485ec0ec0af80a0d63c10e94aebfc59b16aab46b (patch)
tree279ec542bddf3447b2250e2be489fb0e738744c8
parent39f84a94acedf339320137c435515172cfb8261f (diff)
downloadwaybar-mpris-485ec0ec0af80a0d63c10e94aebfc59b16aab46b.tar.gz
waybar-mpris-485ec0ec0af80a0d63c10e94aebfc59b16aab46b.zip
escape double quotes
-rw-r--r--main.go32
1 files changed, 18 insertions, 14 deletions
diff --git a/main.go b/main.go
index 6a16b88..206ea44 100644
--- a/main.go
+++ b/main.go
@@ -150,6 +150,10 @@ func secondsToString(seconds int) string {
// JSON returns json for waybar to consume.
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
out := "{\"class\": \""
if p.Playing {
@@ -177,24 +181,24 @@ func playerJSON(p *player) string {
case "SYMBOL":
items = append(items, symbol)
case "ARTIST":
- if p.Artist != "" {
- items = append(items, p.Artist)
+ if artist != "" {
+ items = append(items, artist)
}
case "ALBUM":
- if p.Album != "" {
- items = append(items, p.Album)
+ if album != "" {
+ items = append(items, album)
}
case "TITLE":
- if p.Title != "" {
- items = append(items, p.Title)
+ if title != "" {
+ items = append(items, title)
}
case "POSITION":
if pos != "" && SHOW_POS {
items = append(items, pos)
}
case "PLAYER":
- if p.Name != "" {
- items = append(items, p.Name)
+ if name != "" {
+ items = append(items, name)
}
}
}
@@ -214,14 +218,14 @@ func playerJSON(p *player) string {
text += v + right
}
out += "\",\"text\":\"" + text + "\","
- out += "\"tooltip\":\"" + strings.ReplaceAll(p.Title, "&", "&amp;") + "\\n"
- if p.Artist != "" {
- out += "by " + strings.ReplaceAll(p.Artist, "&", "&amp;") + "\\n"
+ out += "\"tooltip\":\"" + strings.ReplaceAll(title, "&", "&amp;") + "\\n"
+ if artist != "" {
+ out += "by " + strings.ReplaceAll(artist, "&", "&amp;") + "\\n"
}
- if p.Album != "" {
- out += "from " + strings.ReplaceAll(p.Album, "&", "&amp;") + "\\n"
+ if album != "" {
+ out += "from " + strings.ReplaceAll(album, "&", "&amp;") + "\\n"
}
- out += "(" + p.Name + ")\"}"
+ out += "(" + name + ")\"}"
return out
// return fmt.Sprintf("{\"class\":\"%s\",\"text\":\"%s\",\"tooltip\":\"%s\"}", data["class"], data["text"], data["tooltip"])
// out, err := json.Marshal(data)