From 58c9607edc2cc763cfb9f933ffffeed1b8fddd9c Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Fri, 11 Oct 2024 01:31:05 +0300 Subject: [PATCH] Don't panic on general section missing Fixes #8230. --- alacritty/src/migrate/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/alacritty/src/migrate/mod.rs b/alacritty/src/migrate/mod.rs index ffd0d4b4..58f381de 100644 --- a/alacritty/src/migrate/mod.rs +++ b/alacritty/src/migrate/mod.rs @@ -134,7 +134,11 @@ fn migrate_imports( recursion_limit: usize, ) -> Result<(), String> { // Check if any imports need to be processed. - let imports = match document["general"].get("import").and_then(|i| i.as_array()) { + let imports = match document + .get("general") + .and_then(|general| general.get("import")) + .and_then(|import| import.as_array()) + { Some(array) if !array.is_empty() => array, _ => return Ok(()), }; @@ -315,4 +319,9 @@ root_value = 3 assert_eq!(output, expected); } + + #[test] + fn migrate_empty() { + assert!(migrate_toml(String::new()).unwrap().to_string().is_empty()); + } }