Merge pull request #1340 from CiberNin/fix/editor-crashes

Fix editor crashes from typed input, text, and degenerate geometry
This commit is contained in:
Hakan Seven committed 2026-09-18 18:52:37 +03:00
commit 3c1ad62e9b
12 files changed
+391 -27

No files matched your search

+19
View File
@@ -2460,3 +2460,22 @@ mod region_tests {
}
}
}
#[cfg(test)]
mod degenerate_constraint_tests {
use crate::app::OpenCADStudio;
/// Retaining a zero-length line's size used to hand the solver a NaN
/// Jacobian, and its SVD fallback never returned.
#[test]
fn equal_constraint_with_a_zero_length_line_returns() {
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
app.automation_op(r#"{"op":"run","cmd":"LINE 0,0 0,0 "}"#);
app.automation_op(r#"{"op":"run","cmd":"LINE 5,5 20,7 "}"#);
app.automation_op(r#"{"op":"select","type":"Line"}"#);
app.automation_op(r#"{"op":"run","cmd":"ECONSTRAINT"}"#);
let lines = app.automation_op(r#"{"op":"query","type":"Line","detail":"geometry"}"#);
assert_eq!(lines["ok"], true, "{lines}");
}
}
+20 -2
View File
@@ -1302,8 +1302,9 @@ impl OpenCADStudio {
let all_mode = cmd.starts_with("FINDALL");
let rest = cmd.split_once(' ').map(|(_, r)| r.trim()).unwrap_or("");
// Split at " REPLACE " keyword (case-insensitive)
let (search, replacement) = if let Some(pos) = rest.to_uppercase().find(" REPLACE ")
// Split at " REPLACE " keyword (case-insensitive). ASCII case
// mapping keeps byte offsets valid for slicing `rest`.
let (search, replacement) = if let Some(pos) = rest.to_ascii_uppercase().find(" REPLACE ")
{
(&rest[..pos], Some(rest[pos + 9..].trim()))
} else {
@@ -2386,3 +2387,20 @@ mod align_selected_bounds_tests {
assert_eq!(line_start_x(&app, b), 2.0, "b must keep its offset from a, not collapse onto it");
}
}
#[cfg(test)]
mod find_replace_command_tests {
use super::*;
/// Unicode case mapping can change a string's byte length (`ı` uppercases
/// to `I`), so the REPLACE keyword split must not slice with offsets
/// taken from a case-mapped copy.
#[test]
fn find_replace_accepts_search_text_whose_case_mapping_changes_length() {
for cmd in ["FIND ı REPLACE x", "FINDALL fi REPLACE fi", "FIND ʼn replace n"] {
let mut app = OpenCADStudio::new_for_test();
let i = app.active_tab;
let _ = app.dispatch_inquiry(cmd, i);
}
}
}