Compare commits

...

2 Commits

Author SHA1 Message Date
077b53f6ff cleanup imports
Some checks failed
Test Rust project / test (ubuntu-latest, stable) (push) Failing after 41s
2026-01-27 13:50:00 -07:00
0c78e7834b fix #33 2026-01-27 13:49:46 -07:00
5 changed files with 29 additions and 9 deletions

View File

@@ -18,7 +18,7 @@ use ratatui::{
use crate::app::{
clipboard::Clipboard,
error_msg::StatusMessage,
logic::{self, calc::{Grid, get_header_size}, cell::CellType},
logic::{calc::{Grid, get_header_size}, cell::CellType},
mode::Mode,
screen::ScreenSpace,
};

View File

@@ -851,6 +851,19 @@ fn parse_csv() {
);
}
#[test]
fn invalid_ranges() {
let mut grid = Grid::new();
grid.set_cell("A0", 2.);
grid.set_cell("A1", 1.);
// ASCII to number conversion needs to not overflow
grid.set_cell("B0", "=sum($:A)".to_string());
let cell = grid.get_cell("B0").as_ref().expect("Just set it");
let _ = grid.evaluate(&cell.to_string()).expect("Should evaluate.");
}
#[test]
fn ranges() {
let mut grid = Grid::new();

View File

@@ -24,7 +24,7 @@ impl<'a> CallbackContext<'a> {
let as_index = |s: &str| {
s.char_indices()
// .filter(|f| f.1 as u8 >= 97) // prevent sub with overflow errors
.map(|(idx, c)| (c.to_ascii_lowercase() as usize - 97) + (26 * idx))
.map(|(idx, c)| ((c.to_ascii_lowercase() as usize).saturating_sub(97)) + (26 * idx))
.fold(0, |a, b| a + b)
};
@@ -162,8 +162,8 @@ impl<'a> Context for CallbackContext<'a> {
}
if let Ok(mut trail) = self.eval_breadcrumbs.write() {
let find = trail.iter().filter(|id| *id == identifier).collect::<Vec<&String>>();
if find.len() > 0 {
let find = trail.iter().filter(|id| *id == identifier).count();
if find > 0 {
// recursion detected
return None;
} else {
@@ -195,7 +195,7 @@ impl<'a> Context for CallbackContext<'a> {
},
Err(e) => {
match e {
EvalexprError::VariableIdentifierNotFound(_) => {
EvalexprError::VariableIdentifierNotFound(_err) => {
// If the variable isn't found, that's ~~probably~~ because
// of recursive reference, considering all references
// are grabbed straight from the table.
@@ -217,8 +217,14 @@ impl<'a> Context for CallbackContext<'a> {
CellType::Number(e) => vals.push(Value::Float(*e)),
CellType::String(s) => vals.push(Value::String(s.to_owned())),
CellType::Equation(eq) => {
if let Ok(val) = eval_with_context(&eq[1..], self) {
vals.push(val);
match eval_with_context(&eq[1..], self) {
Ok(val) => vals.push(val),
Err(_err) => {
// At this point we are getting an error because
// recursion protection made this equation return
// None. We now don't get any evaluation.
return None
},
}
}
}
@@ -272,6 +278,7 @@ impl ExtractionContext {
pub fn dump_vars(&self) -> Vec<String> {
if let Ok(r) = self.var_registry.read() { r.clone() } else { Vec::new() }
}
#[allow(dead_code)]
pub fn dump_fns(&self) -> Vec<String> {
if let Ok(r) = self.fn_registry.read() { r.clone() } else { Vec::new() }
}

View File

@@ -15,7 +15,7 @@ use crate::app::{
app::App,
error_msg::StatusMessage,
logic::{
calc::{CSV_EXT, CUSTOM_EXT, Grid, LEN},
calc::{Grid, LEN},
cell::CellType,
},
};

View File

@@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::RwLock};
use ratatui::prelude;
use crate::app::logic::calc::{self, LEN};
use crate::app::logic::calc::LEN;
pub struct ScreenSpace {
/// This is measured in cells.