mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-10 10:03:34 +00:00
address review: empty-document range cannot overflow in set_attr
This commit is contained in:
@@ -977,7 +977,8 @@ impl TextDoc {
|
||||
if r.start >= r.end && n > 0 {
|
||||
return Ok(true);
|
||||
}
|
||||
let range = r.start..r.end.max(r.start + usize::from(n == 0));
|
||||
// Empty text: apply_style ignores the bounds, so a fixed range avoids `start + 1` overflow.
|
||||
let range = if n == 0 { 0..1 } else { r.start..r.end };
|
||||
// Check every affected run first, so a value one run refuses changes none of them.
|
||||
let mut err = None;
|
||||
self.apply_style(range.clone(), |s| {
|
||||
@@ -1377,6 +1378,12 @@ mod tests {
|
||||
assert_eq!(doc.style_at(0).variations.len(), MAX_VARIATION_AXES);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_document_accepts_an_extreme_range_without_overflow() {
|
||||
let mut doc = TextDoc::plain("");
|
||||
assert!(doc.set_attr("size", &J::from(20), Some(usize::MAX..usize::MAX)).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixed_line_breaks_keep_original_byte_and_character_ranges() {
|
||||
let text = "é\r\nβ\rx\n\n";
|
||||
|
||||
Reference in New Issue
Block a user