From 7654d4924691f612639f02ff34345926ba47ec7f Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sun, 24 Sep 2017 20:09:44 -0700 Subject: [PATCH] Fixed a bug where playlists that have spaces in their name were unusable --- src/api.rs | 10 ++++++++++ src/errors.rs | 1 + 2 files changed, 11 insertions(+) diff --git a/src/api.rs b/src/api.rs index 390febe..15c6f8a 100644 --- a/src/api.rs +++ b/src/api.rs @@ -573,6 +573,11 @@ fn read_playlist(request: &mut Request, db: &DB) -> IronResult { _ => return Err(Error::from(ErrorKind::MissingPlaylistName).into()), }; + let playlist_name = match percent_decode(playlist_name.as_bytes()).decode_utf8() { + Ok(s) => s, + Err(e) => return Err(Error::from(ErrorKind::EncodingError).into()), + }; + let songs = playlist::read_playlist(&playlist_name, &username, db)?; let result_json = serde_json::to_string(&songs); let result_json = match result_json { @@ -595,6 +600,11 @@ fn delete_playlist(request: &mut Request, db: &DB) -> IronResult { _ => return Err(Error::from(ErrorKind::MissingPlaylistName).into()), }; + let playlist_name = match percent_decode(playlist_name.as_bytes()).decode_utf8() { + Ok(s) => s, + Err(e) => return Err(Error::from(ErrorKind::EncodingError).into()), + }; + playlist::delete_playlist(&playlist_name, &username, db)?; Ok(Response::with(status::Ok)) diff --git a/src/errors.rs b/src/errors.rs index 1607e80..e90e231 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -48,6 +48,7 @@ error_chain! { FileNotFound {} MissingIndexVersion {} MissingPlaylistName {} + EncodingError {} } }