From 5a01301b74e9f0985c6992a0b8bc489a9e27b340 Mon Sep 17 00:00:00 2001 From: Pavlo Rudyi Date: Mon, 21 Sep 2020 09:41:52 +0000 Subject: [PATCH 1/4] fix #507 - the crash caused by long track title --- src/audio/player.rs | 2 +- src/utils.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audio/player.rs b/src/audio/player.rs index a0efd524..152e97d5 100644 --- a/src/audio/player.rs +++ b/src/audio/player.rs @@ -386,7 +386,7 @@ impl SongTitle { /// Returns path for current title fn get_path(&self) -> Option { if let Some(title) = &self.current_title { - let title = utils::simplify_string(title.to_string()); + let title = &utils::simplify_string(title.to_string())[..200]; let mut path = path::CACHE.clone(); path.push("recording"); diff --git a/src/utils.rs b/src/utils.rs index a8a03564..1fd16419 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -96,7 +96,7 @@ where } pub fn simplify_string(s: String) -> String { - s.replace(&['/', '\\', ':', '<', '>', '\"', '|', '?', '*', '.'] as &[_], "") + s.replace(&['/', '\\0', '\\', ':', '<', '>', '\"', '|', '?', '*', '.'] as &[_], "") } pub fn station_subtitle(country: &str, state: &str, votes: i32) -> String { -- GitLab From ab52b4d1ed8061c6accc3dabe2d37c636c202fff Mon Sep 17 00:00:00 2001 From: Pavlo Rudyi Date: Mon, 21 Sep 2020 19:46:22 +0000 Subject: [PATCH 2/4] avoid panic on short titles --- src/audio/player.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio/player.rs b/src/audio/player.rs index 152e97d5..00e43bf6 100644 --- a/src/audio/player.rs +++ b/src/audio/player.rs @@ -386,7 +386,7 @@ impl SongTitle { /// Returns path for current title fn get_path(&self) -> Option { if let Some(title) = &self.current_title { - let title = &utils::simplify_string(title.to_string())[..200]; + let title = &utils::simplify_string(title.to_string())[..utils::simplify_string(title.to_string()).len().min(200)]; let mut path = path::CACHE.clone(); path.push("recording"); -- GitLab From 502386e68b62da6bc903294cf2730e0cab6ee45c Mon Sep 17 00:00:00 2001 From: Pavlo Rudyi Date: Mon, 28 Sep 2020 10:23:14 +0000 Subject: [PATCH 3/4] now supports Unicode characters --- src/audio/player.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/audio/player.rs b/src/audio/player.rs index 00e43bf6..e6e1f9b8 100644 --- a/src/audio/player.rs +++ b/src/audio/player.rs @@ -386,7 +386,10 @@ impl SongTitle { /// Returns path for current title fn get_path(&self) -> Option { if let Some(title) = &self.current_title { - let title = &utils::simplify_string(title.to_string())[..utils::simplify_string(title.to_string()).len().min(200)]; + let title_raw = utils::simplify_string(title.to_string()); + let title_vec = title_raw.chars().collect::>(); + let cut_to_length = title_vec.len().min(200); + let title = text_vec[..cut_to_length].iter().cloned().collect::(); let mut path = path::CACHE.clone(); path.push("recording"); -- GitLab From bd74041c56d3498c1cb7ec6fa7b18145426a9a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4cker?= Date: Sun, 4 Oct 2020 09:31:16 +0000 Subject: [PATCH 4/4] Add comments --- src/audio/player.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/audio/player.rs b/src/audio/player.rs index e6e1f9b8..17ac3f8a 100644 --- a/src/audio/player.rs +++ b/src/audio/player.rs @@ -386,7 +386,9 @@ impl SongTitle { /// Returns path for current title fn get_path(&self) -> Option { if let Some(title) = &self.current_title { + // Remove unsupported characters from the file name let title_raw = utils::simplify_string(title.to_string()); + // Limit file name to 200 chars let title_vec = title_raw.chars().collect::>(); let cut_to_length = title_vec.len().min(200); let title = text_vec[..cut_to_length].iter().cloned().collect::(); -- GitLab