Escape output with html_escape

This commit is contained in:
Erwin Boskma 2022-02-13 13:49:41 +01:00
parent 401560b611
commit 3247635cb4
Signed by: erwin
GPG key ID: 270B20D17394F7E5
4 changed files with 23 additions and 8 deletions

16
Cargo.lock generated
View file

@ -315,6 +315,7 @@ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
"color-eyre", "color-eyre",
"html-escape",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
@ -346,6 +347,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "html-escape"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "816ea801a95538fc5f53c836697b3f8b64a9d664c4f0b91efe1fe7c92e4dbcb7"
dependencies = [
"utf8-width",
]
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.5" version = "0.2.5"
@ -1203,6 +1213,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "utf8-width"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cf7d77f457ef8dfa11e4cd5933c5ddb5dc52a94664071951219a97710f0a32b"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"

View file

@ -9,6 +9,7 @@ edition = "2021"
anyhow = "1.0.52" anyhow = "1.0.52"
clap = "3.0.0-beta.2" clap = "3.0.0-beta.2"
color-eyre = "0.6.0" color-eyre = "0.6.0"
html-escape = "0.2.9"
reqwest = { version = "0.11.4", features = ["blocking", "json"] } reqwest = { version = "0.11.4", features = ["blocking", "json"] }
serde = { version = "1.0.126", features = ["derive"] } serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64" serde_json = "1.0.64"

View file

@ -55,7 +55,7 @@
devShell = with pkgs; mkShell { devShell = with pkgs; mkShell {
inherit buildInputs; inherit buildInputs;
nativeBuildInputs = [ cargo-edit cargo-expand cargo-diet cargo-feature cargo-outdated pre-commit jq ] ++ nativeBuildInputs; nativeBuildInputs = [ cargo-edit cargo-expand cargo-diet cargo-feature cargo-outdated rust-analyzer pre-commit jq ] ++ nativeBuildInputs;
}; };
}); });

View file

@ -158,14 +158,12 @@ fn get_now_playing(host: String, entity: String, insecure: bool, token: String)
format!("{volume}{artist} - {title}") format!("{volume}{artist} - {title}")
}; };
println!("{}", now_playing); println!("{}", html_escape::encode_text(&now_playing));
} else { } else {
println!( let state = response["state"]
"Sonos {}",
response["state"]
.as_str() .as_str()
.map_or("state unknown", |state| state) .map_or("State unknown", |state| state);
); println!("Sonos {}", html_escape::encode_text(state));
} }
Ok(()) Ok(())