From f9e4a5d43843f556ab59c0035e82391e6ec0f2b4 Mon Sep 17 00:00:00 2001 From: Andreas Backx Date: Sat, 20 May 2023 18:51:16 +0100 Subject: [PATCH] Fixed problem with HTML escaping for Waybar. Reported here too: https://github.com/Alexays/Waybar/issues/2067 --- CHANGELOG.md | 3 +++ Cargo.lock | 18 +++++++++++++++++- Cargo.toml | 3 ++- src/commands/output.rs | 6 +++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 895d169..3c6d79f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [0.2.4] - 2023-05-20 +### Changed +- Fixed Waybar output problem with HTML escaping. ## [0.2.3] - 2022-05-29 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 51d1599..766c6f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -682,6 +682,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "html-escape" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" +dependencies = [ + "utf8-width", +] + [[package]] name = "http" version = "0.2.7" @@ -1719,11 +1728,12 @@ dependencies = [ [[package]] name = "spotifatius" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "clap", "futures", + "html-escape", "prost", "rspotify", "serde", @@ -2208,6 +2218,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8-width" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" + [[package]] name = "valuable" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index fc90cac..7514f07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,13 @@ homepage = "https://github.com/AndreasBackx/spotifatius" keywords = ["spotify", "waybar", "polybar"] license = "MIT" name = "spotifatius" -version = "0.2.3" +version = "0.2.4" [dependencies] anyhow = "1.0.41" clap = {version = "3.1.18", features = ["derive"]} futures = {version = "0.3", default-features = false} +html-escape = "0.2.13" # Don't use prost's `prost-derive` because it's unused. prost = {version = "0.10.4", default-features = false, features = ["std"]} rspotify = {version = "0.11.0", features = [ diff --git a/src/commands/output.rs b/src/commands/output.rs index 39f1f6f..d385813 100644 --- a/src/commands/output.rs +++ b/src/commands/output.rs @@ -28,7 +28,11 @@ impl OutputFormatter { pub fn print(&self, output: Output) -> Result<()> { match self.output_type { OutputType::Waybar => { - let json = serde_json::to_string(&output)?; + let json = serde_json::to_string(&Output { + text: html_escape::encode_text(&output.text.to_string()) + .into(), + ..output + })?; println!("{}", json); } OutputType::Polybar => {