fix(field): bound the Field dialog's automation indices; ASCII browse button

#1585's field_dialog action stored any index it was given, and the dialog
indexes its category, case, size, named-type, formula, precision and plot
scale lists with them, so an out-of-range value panicked while drawing.
They are checked against the list lengths now. The hyperlink browse
button drew a glyph (…) that is tofu without the font, and two of the
new local_header_dates calls were mis-indented.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-02 14:17:48 +03:00
1 parent 0de1e91f99
commit a21aef2a11
3 files changed
+20 -12

No files matched your search

+17 -9
View File
@@ -987,30 +987,38 @@ impl OpenCADStudio {
use crate::ui::window::field_dialog::{self as fd, FieldDialogMsg as F};
let value = string(req, "value")?;
let (key, v) = value.split_once('=').unwrap_or((value, ""));
let index = || v.parse::<usize>().map_err(|_| failure("invalid_value", "index expected"));
// The dialog indexes its lists with these, so one out of range
// would panic while it draws.
let index = |len: usize| {
v.parse::<usize>()
.ok()
.filter(|i| *i < len)
.ok_or_else(|| failure("invalid_value", "index out of range"))
};
let named_len = self.field_dialog.as_ref().map_or(0, |d| d.named_names.len());
let known = |list: &[&'static str]| {
list.iter().copied().find(|n| n.eq_ignore_ascii_case(v)).ok_or_else(|| failure("invalid_value", "unknown name"))
};
Message::FieldDialog(match key {
"category" => F::Category(index()?),
"category" => F::Category(index(fd::CATEGORIES.len())?),
"name" => F::Name(known(&fd::fields_of(0))?),
"date" => F::DateFormat(v.into()),
"case" => F::TextCase(index()?),
"case" => F::TextCase(index(fd::TEXT_CASES.len())?),
"file" => F::FileParts(v.parse::<u8>().map_err(|_| failure("invalid_value", "1|2|3"))?),
"ext" => F::FileExtension(v == "1"),
"size" => F::SizeUnit(index()?),
"size" => F::SizeUnit(index(fd::SIZE_UNITS.len())?),
"sysvar" => F::SysVar(v.into()),
"diesel" => F::Diesel(v.into()),
"named_type" => F::NamedType(index()?),
"named" => F::Named(index()?),
"named_type" => F::NamedType(index(fd::NAMED_TYPES.len())?),
"named" => F::Named(index(named_len)?),
"prop" => F::ObjectProp(known(&["Area", "Center", "Circumference", "Diameter", "EndPoint", "Length", "Radius", "StartPoint"])?),
"select_object" => F::SelectObject,
"formula" => F::Formula(v.into()),
"formula_format" => F::FormulaFormat(index()?),
"precision" => F::FormulaPrecision(index()?),
"formula_format" => F::FormulaFormat(index(codec::fields::FORMULA_FORMATS.len())?),
"precision" => F::FormulaPrecision(index(fd::FORMULA_PRECISIONS.len())?),
"link_text" => F::HyperlinkText(v.into()),
"link_url" => F::HyperlinkUrl(v.into()),
"plot_scale" => F::PlotScale(index()?),
"plot_scale" => F::PlotScale(index(codec::fields::PLOT_SCALE_FORMATS.len())?),
_ => return Err(failure("invalid_value", "Unknown field dialog key")),
})
}