From 5bf12f5281730ee1787354785793024ed39ff4c2 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Thu, 27 Jan 2022 17:59:32 +0000 Subject: [PATCH] escape double quotes --- main.go | 32 ++++++++++++++++++-------------- nohup.out | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 nohup.out 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, "&", "&") + "\\n" - if p.Artist != "" { - out += "by " + strings.ReplaceAll(p.Artist, "&", "&") + "\\n" + out += "\"tooltip\":\"" + strings.ReplaceAll(title, "&", "&") + "\\n" + if artist != "" { + out += "by " + strings.ReplaceAll(artist, "&", "&") + "\\n" } - if p.Album != "" { - out += "from " + strings.ReplaceAll(p.Album, "&", "&") + "\\n" + if album != "" { + out += "from " + strings.ReplaceAll(album, "&", "&") + "\\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) diff --git a/nohup.out b/nohup.out new file mode 100644 index 0000000..e584cec --- /dev/null +++ b/nohup.out @@ -0,0 +1,19 @@ +[2022-01-27 17:59:22.894] [info] Resources files: /home/hrfee/.config/waybar/config.json, /home/hrfee/.config/waybar/style.css + +(waybar:72760): Gtk-WARNING **: 17:59:22.895: Theme parsing error: style.css:3:21: Not using units is deprecated. Assuming 'px'. +[2022-01-27 17:59:22.907] [warning] For a functional tray you must have libappindicator-* installed and export XDG_CURRENT_DESKTOP=Unity + +** (waybar:72760): WARNING **: 17:59:22.931: gtk-layer-shell v0.6.0 may not work on GTK v3.24.31. If you experience crashes, check https://github.com/wmww/gtk-layer-shell/blob/master/compatibility.md +[2022-01-27 17:59:23.001] [info] Bar configured (width: 3840, height: 54) for output: DP-3 + +** (waybar:72760): WARNING **: 17:59:23.014: Status Notifier Item with bus name ':1.53' and object path '/org/ayatana/NotificationItem/nm_applet' is already registered + +** (waybar:72760): WARNING **: 17:59:23.014: Status Notifier Item with bus name ':1.51' and object path '/org/ayatana/NotificationItem/_modules_kdeconnect_devices_d67d80726287e2f8' is already registered + +** (waybar:72760): WARNING **: 17:59:23.045: Status Notifier Item with bus name ':1.66' and object path '/org/ayatana/NotificationItem/discord1' is already registered + +** (waybar:72760): WARNING **: 17:59:23.054: Status Notifier Item with bus name ':1.66' and object path '/org/ayatana/NotificationItem/discord1' is already registered + +** (waybar:72760): WARNING **: 17:59:23.054: Status Notifier Item with bus name ':1.53' and object path '/org/ayatana/NotificationItem/nm_applet' is already registered + +** (waybar:72760): WARNING **: 17:59:23.054: Status Notifier Item with bus name ':1.51' and object path '/org/ayatana/NotificationItem/_modules_kdeconnect_devices_d67d80726287e2f8' is already registered