Custom Module: Text Rendering Issue with `&` Character in the `text` JSON Field
Overview:
When the JSON return to a custom module contains the character &, it appears to break the JSON parsing on the text field of the custom module and the contents of the text field aren't updated. If the value for text is initially set containing the & character, the custom module's text field is blank/null and only the background is rendered.
Reproduction:
I have a custom/media module defined as the following:
"custom/media": {
"interval": 1,
"format": "{}",
"tooltip": true,
"return-type": "json",
"max-length": 40,
"on-click": "playerctl -p spotify play-pause",
"on-click-right": "playerctl -p spotify stop",
"smooth-scrolling-threshold": 10,
"on-scroll-up": "playerctl -p spotify next",
"on-scroll-down": "playerctl -p spotify previous",
"exec": "pwsh -c ~/fetch-media.ps1",
},
This is the contents of the PowerShell script:
try
{
$playerStatus=$(playerctl -p spotify status)
$artist = $(playerctl metadata -p spotify --format "{{ artist }}").Trim()
$title = $(playerctl metadata -p spotify --format "{{ title }}").Trim()
$artUrl = $(playerctl metadata -p spotify --format "{{ mpris:artUrl }}")
if($playerStatus.Contains("Playing")) {
return "{`"text`":`" $($artist) - $($title)`"}"
}
else {
return "{`"text`":`" $($artist) - $($title)`"}"
}
}
catch
{
return "{`"text`":`" Spotify not playing...`"}"
}
An example title that causes the text rendering on Waybar to break is {"text":" Of Mice & Men - Pulling Teeth"} or {"text":" Of Mice & Men - Timeless"}. (This was obtained by running the script and grabbing the JSON output from the terminal, during repro.)
Remediation[s]:
The rendering issue (of it only showing the previous song before the current - or of empty/null content on init) is "resolved" by selecting the next song, as the next artist/song doesn't contain the & character.
Technical Information:
Version: Waybar v0.14.0 Platform: Arch Linux
More Information: Feel free to let me know if you need/require more information.
The problem is that the GTK label uses markup parsing, so to get the & symbol to display, you need to replace instances of the bare ampersand with "& amp ;" (without spaces) in your power-shell script before passing it to waybar.