forked from 1b-agent/opencadstudio-upstream
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
0de1e91f99
commit
a21aef2a11
3 files changed
+20
-12
No files matched your search
@@ -987,30 +987,38 @@ impl OpenCADStudio {
|
|||||||
use crate::ui::window::field_dialog::{self as fd, FieldDialogMsg as F};
|
use crate::ui::window::field_dialog::{self as fd, FieldDialogMsg as F};
|
||||||
let value = string(req, "value")?;
|
let value = string(req, "value")?;
|
||||||
let (key, v) = value.split_once('=').unwrap_or((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]| {
|
let known = |list: &[&'static str]| {
|
||||||
list.iter().copied().find(|n| n.eq_ignore_ascii_case(v)).ok_or_else(|| failure("invalid_value", "unknown name"))
|
list.iter().copied().find(|n| n.eq_ignore_ascii_case(v)).ok_or_else(|| failure("invalid_value", "unknown name"))
|
||||||
};
|
};
|
||||||
Message::FieldDialog(match key {
|
Message::FieldDialog(match key {
|
||||||
"category" => F::Category(index()?),
|
"category" => F::Category(index(fd::CATEGORIES.len())?),
|
||||||
"name" => F::Name(known(&fd::fields_of(0))?),
|
"name" => F::Name(known(&fd::fields_of(0))?),
|
||||||
"date" => F::DateFormat(v.into()),
|
"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"))?),
|
"file" => F::FileParts(v.parse::<u8>().map_err(|_| failure("invalid_value", "1|2|3"))?),
|
||||||
"ext" => F::FileExtension(v == "1"),
|
"ext" => F::FileExtension(v == "1"),
|
||||||
"size" => F::SizeUnit(index()?),
|
"size" => F::SizeUnit(index(fd::SIZE_UNITS.len())?),
|
||||||
"sysvar" => F::SysVar(v.into()),
|
"sysvar" => F::SysVar(v.into()),
|
||||||
"diesel" => F::Diesel(v.into()),
|
"diesel" => F::Diesel(v.into()),
|
||||||
"named_type" => F::NamedType(index()?),
|
"named_type" => F::NamedType(index(fd::NAMED_TYPES.len())?),
|
||||||
"named" => F::Named(index()?),
|
"named" => F::Named(index(named_len)?),
|
||||||
"prop" => F::ObjectProp(known(&["Area", "Center", "Circumference", "Diameter", "EndPoint", "Length", "Radius", "StartPoint"])?),
|
"prop" => F::ObjectProp(known(&["Area", "Center", "Circumference", "Diameter", "EndPoint", "Length", "Radius", "StartPoint"])?),
|
||||||
"select_object" => F::SelectObject,
|
"select_object" => F::SelectObject,
|
||||||
"formula" => F::Formula(v.into()),
|
"formula" => F::Formula(v.into()),
|
||||||
"formula_format" => F::FormulaFormat(index()?),
|
"formula_format" => F::FormulaFormat(index(codec::fields::FORMULA_FORMATS.len())?),
|
||||||
"precision" => F::FormulaPrecision(index()?),
|
"precision" => F::FormulaPrecision(index(fd::FORMULA_PRECISIONS.len())?),
|
||||||
"link_text" => F::HyperlinkText(v.into()),
|
"link_text" => F::HyperlinkText(v.into()),
|
||||||
"link_url" => F::HyperlinkUrl(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")),
|
_ => return Err(failure("invalid_value", "Unknown field dialog key")),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -765,7 +765,7 @@ pub fn load_bytes(name: &str, bytes: Vec<u8>) -> Result<CadDocument, String> {
|
|||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
fix_viewport_status_flags(&mut doc);
|
fix_viewport_status_flags(&mut doc);
|
||||||
fix_current_style_names(&mut doc);
|
fix_current_style_names(&mut doc);
|
||||||
crate::entities::field::local_header_dates(&mut doc);
|
crate::entities::field::local_header_dates(&mut doc);
|
||||||
Ok(doc)
|
Ok(doc)
|
||||||
}
|
}
|
||||||
"dxf" => {
|
"dxf" => {
|
||||||
@@ -777,7 +777,7 @@ pub fn load_bytes(name: &str, bytes: Vec<u8>) -> Result<CadDocument, String> {
|
|||||||
fix_dxf_layout_plot_settings(&mut doc);
|
fix_dxf_layout_plot_settings(&mut doc);
|
||||||
fix_viewport_status_flags(&mut doc);
|
fix_viewport_status_flags(&mut doc);
|
||||||
fix_current_style_names(&mut doc);
|
fix_current_style_names(&mut doc);
|
||||||
crate::entities::field::local_header_dates(&mut doc);
|
crate::entities::field::local_header_dates(&mut doc);
|
||||||
Ok(doc)
|
Ok(doc)
|
||||||
}
|
}
|
||||||
_ => Err(format!("Unsupported file format: .{ext}")),
|
_ => Err(format!("Unsupported file format: .{ext}")),
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ fn format_panel<'a>(state: &'a FieldDialogState) -> Element<'a, Message> {
|
|||||||
.font(iced::Font::MONOSPACE)
|
.font(iced::Font::MONOSPACE)
|
||||||
.style(field_style)
|
.style(field_style)
|
||||||
.on_input(|v| msg(FieldDialogMsg::HyperlinkUrl(v))),
|
.on_input(|v| msg(FieldDialogMsg::HyperlinkUrl(v))),
|
||||||
button(text("…").size(12))
|
button(text("...").size(12))
|
||||||
.on_press(msg(FieldDialogMsg::BrowseHyperlink))
|
.on_press(msg(FieldDialogMsg::BrowseHyperlink))
|
||||||
.style(button_style(false))
|
.style(button_style(false))
|
||||||
.padding([5, 10]),
|
.padding([5, 10]),
|
||||||
|
|||||||
Reference in new issue
Block a user