From 07853f07009c7aa96b6d2587dc1e6cb440622ef0 Mon Sep 17 00:00:00 2001 From: alexandre pasmantier Date: Tue, 15 Jul 2025 19:04:40 +0200 Subject: [PATCH] fix(history): short-circuit `add_entry` when history size is zero Fixes #646 --- television/history.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/television/history.rs b/television/history.rs index 04808a0..8ae47f9 100644 --- a/television/history.rs +++ b/television/history.rs @@ -80,6 +80,9 @@ impl History { /// Add a new history entry, if it's not a duplicate. pub fn add_entry(&mut self, query: String, channel: String) -> Result<()> { + if self.max_size == 0 { + return Ok(()); + } // Don't add empty queries if query.trim().is_empty() { return Ok(()); @@ -734,4 +737,19 @@ mod tests { // Calling get_next without any previous navigation should return None assert!(hist.get_next_entry().is_none()); } + + #[test] + fn add_entry_with_history_size_zero() { + let dir = tempdir().expect("failed to create tempdir"); + let mut hist = History::new(0, "files", false, dir.path()); + + // Adding an entry should not change the history + hist.add_entry("file1".into(), "files".into()).unwrap(); + assert!(hist.is_empty()); + assert_eq!(hist.len(), 0); + + // Navigation should return None + assert!(hist.get_previous_entry().is_none()); + assert!(hist.get_next_entry().is_none()); + } }