FIX: Forbid unwrap, expect and panic in the base code

This commit is contained in:
Nicolás Hatcher
2024-11-16 14:18:12 +01:00
committed by Nicolás Hatcher Andrés
parent bdd2c8fe04
commit 49ae2d8915
43 changed files with 341 additions and 128 deletions

View File

@@ -1,3 +1,6 @@
#![allow(clippy::panic)]
#![allow(clippy::expect_used)]
//! Produces documentation of all the implemented IronCalc functions
//! and saves the result to functions.md
//!

View File

@@ -1,3 +1,6 @@
#![allow(clippy::unwrap_used)]
#![allow(clippy::panic)]
//! Tests an Excel xlsx file.
//! Returns a list of differences in json format.
//! Saves an IronCalc version

View File

@@ -1,3 +1,6 @@
#![allow(clippy::unwrap_used)]
#![allow(clippy::panic)]
//! Tests an Excel xlsx file.
//! Returns a list of differences in json format.
//! Saves an IronCalc version

View File

@@ -1,3 +1,5 @@
#![allow(clippy::unwrap_used)]
use std::path::Path;
use ironcalc_base::cell::CellValue;

View File

@@ -1,3 +1,5 @@
#![allow(clippy::unwrap_used)]
mod _rels;
mod doc_props;
mod escape;

View File

@@ -1,3 +1,4 @@
#![allow(clippy::unwrap_used)]
//! <sheet name="Sheet1" sheetId="1" r:id="rId1"/>
//! A workbook is composed of workbook-level properties and a collection of 1 or more sheets.

View File

@@ -1,3 +1,6 @@
#![allow(clippy::unwrap_used)]
#![allow(clippy::panic)]
//! # A note on shared formulas
//! Although both Excel and IronCalc uses shared formulas they are used in a slightly different way that cannot be mapped 1-1
//! In IronCalc _all_ formulas are shared and there is a list of shared formulas much like there is a list of shared strings.

View File

@@ -1,3 +1,5 @@
#![allow(clippy::unwrap_used)]
use core::cmp::max;
use core::cmp::min;

View File

@@ -38,6 +38,7 @@ fn read_shared_strings_from_string(text: &str) -> Result<Vec<String>, XlsxError>
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]

View File

@@ -41,29 +41,35 @@ pub(crate) fn load_table<R: Read + std::io::Seek>(
// They also need to be different from any defined name
let name = table
.attribute("name")
.expect("Missing table name")
.ok_or_else(|| XlsxError::Xml("Corrupt XML structure: missing table name".to_string()))?
.to_string();
let display_name = table
.attribute("name")
.expect("Missing table display name")
.ok_or_else(|| {
XlsxError::Xml("Corrupt XML structure: missing table display name".to_string())
})?
.to_string();
// Range of the table, including the totals if any and headers.
let reference = table
.attribute("ref")
.expect("Missing table ref")
.ok_or_else(|| XlsxError::Xml("Corrupt XML structure: missing table ref".to_string()))?
.to_string();
// Either 0 or 1, indicates if the table has a formula for totals at the bottom of the table
let totals_row_count = match table.attribute("totalsRowCount") {
Some(s) => s.parse::<u32>().expect("Invalid totalsRowCount"),
Some(s) => s.parse::<u32>().map_err(|_| {
XlsxError::Xml("Corrupt XML structure: Invalid totalsRowCount".to_string())
})?,
None => 0,
};
// Either 0 or 1, indicates if the table has headers at the top of the table
let header_row_count = match table.attribute("headerRowCount") {
Some(s) => s.parse::<u32>().expect("Invalid headerRowCount"),
Some(s) => s.parse::<u32>().map_err(|_| {
XlsxError::Xml("Corrupt XML structure: Invalid headerRowCount".to_string())
})?,
None => 1,
};
@@ -125,9 +131,15 @@ pub(crate) fn load_table<R: Read + std::io::Seek>(
.collect::<Vec<Node>>();
let mut columns = Vec::new();
for table_column in table_column {
let column_name = table_column.attribute("name").expect("Missing column name");
let id = table_column.attribute("id").expect("Missing column id");
let id = id.parse::<u32>().expect("Invalid id");
let column_name = table_column.attribute("name").ok_or_else(|| {
XlsxError::Xml("Corrupt XML structure: missing column name".to_string())
})?;
let id = table_column.attribute("id").ok_or_else(|| {
XlsxError::Xml("Corrupt XML structure: missing column id".to_string())
})?;
let id = id
.parse::<u32>()
.map_err(|_| XlsxError::Xml("Corrupt XML structure: invalid id".to_string()))?;
// style index of the header row of the table
let header_row_dxf_id = if let Some(index_str) = table_column.attribute("headerRowDxfId") {

View File

@@ -1,3 +1,5 @@
#![allow(clippy::unwrap_used)]
use colors::{get_indexed_color, get_themed_color};
use roxmltree::{ExpandedName, Node};

View File

@@ -1,3 +1,5 @@
#![allow(clippy::unwrap_used)]
use std::{collections::HashMap, io::Read, num::ParseIntError};
use ironcalc_base::{
@@ -1037,7 +1039,10 @@ pub(super) fn load_sheets<R: Read + std::io::Seek>(
name: sheet_name.to_string(),
id: sheet.sheet_id,
state: state.clone(),
comments: comments.get(rel_id).expect("").to_vec(),
comments: comments
.get(rel_id)
.ok_or_else(|| XlsxError::Xml("Corrupt XML structure".to_string()))?
.to_vec(),
};
let (s, is_selected) =
load_sheet(archive, &path, settings, worksheets, tables, shared_strings)?;