Skip to content

Commit

Permalink
fix device_name escaping (Spotifyd#326)
Browse files Browse the repository at this point in the history
* fix device_name escaping

This commit encodes the device_name before sending it over as a query value to the spotify web api. Device names containing special characters should not crash the daemon anymore.
  • Loading branch information
Sven Lechner committed Sep 23, 2019
1 parent 1197e00 commit 10fc843
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 37 deletions.
54 changes: 19 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ keyring = { version = "0.7.1", optional = true }
lazy_static = "1.4.0"
libc = "0.2"
log = "0.4.6"
percent-encoding = "2.1.0"
rspotify = "0.2.5"
serde = { version = "1.0.99", features = ["derive"] }
serde_ini = "0.2.0"
Expand Down
5 changes: 3 additions & 2 deletions src/dbus_mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use librespot::{
},
};
use log::{info, warn};
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use rspotify::spotify::{
client::Spotify, oauth2::TokenInfo as RspotifyToken, senum::*, util::datetime_to_timestamp,
};
Expand Down Expand Up @@ -121,7 +122,7 @@ fn create_dbus_server(
macro_rules! spotify_api_method {
([ $sp:ident, $device:ident $(, $m:ident: $t:ty)*] $f:expr) => {
{
let device_name = device_name.clone();
let device_name = utf8_percent_encode(&device_name, NON_ALPHANUMERIC).to_string();
let token = api_token.clone();
move |m| {
let (p, c) = oneshot::channel();
Expand All @@ -143,7 +144,7 @@ fn create_dbus_server(

macro_rules! spotify_api_property {
([ $sp:ident, $device:ident] $f:expr) => {{
let device_name = device_name.clone();
let device_name = utf8_percent_encode(&device_name, NON_ALPHANUMERIC).to_string();
let token = api_token.clone();
move |i, _| {
let $sp = create_spotify_api(&token);
Expand Down

0 comments on commit 10fc843

Please sign in to comment.