From 2ed77aef1dc9241c169c9e441aeb53f5a01932a0 Mon Sep 17 00:00:00 2001 From: Maxime Jacob Date: Tue, 14 May 2024 10:13:49 -0400 Subject: [PATCH] Fix panic when exploring empty dictionary (#12860) - fixes #12841 # Description Add boundary checks to ensure that the row and column chosen in RecordView are not over the length of the possible row and columns. If we are out of bounds, we default to Value::nothing. # Tests + Formatting Tests ran and formatting done --- crates/nu-explore/src/views/record/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/nu-explore/src/views/record/mod.rs b/crates/nu-explore/src/views/record/mod.rs index 6534ba35893..0ed8e3e761f 100644 --- a/crates/nu-explore/src/views/record/mod.rs +++ b/crates/nu-explore/src/views/record/mod.rs @@ -20,7 +20,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use nu_color_config::{get_color_map, StyleComputer}; use nu_protocol::{ engine::{EngineState, Stack}, - Record, Value, + Record, Span, Value, }; use ratatui::{layout::Rect, widgets::Block}; use std::{borrow::Cow, collections::HashMap}; @@ -180,7 +180,11 @@ impl<'a> RecordView<'a> { Orientation::Left => (column, row), }; - layer.records[row][column].clone() + if layer.records.len() > row && layer.records[row].len() > column { + layer.records[row][column].clone() + } else { + Value::nothing(Span::unknown()) + } } fn create_tablew(&'a self, cfg: ViewConfig<'a>) -> TableW<'a> {