mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
docx: count chart axis format characters like the model
The reader counted UTF-8 bytes against 255 while the model keeps 128 characters, so a CJK axis format was written and then dropped on reading. Use MAX_FMT. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
b6a2df0c1d
commit
4d8273712e
@@ -677,6 +677,21 @@ mod tests {
|
||||
assert_eq!(spec_of(&parse(&plain)), Some(plain));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_axis_format_is_limited_in_characters_not_bytes() {
|
||||
use craft_wordmodel::chart::MAX_FMT;
|
||||
let cjk = format!("0\"{}\"", "\u{5143}".repeat(90));
|
||||
let ascii = format!("0\"{}\"", "x".repeat(90));
|
||||
for fmt in [cjk, ascii] {
|
||||
assert!(fmt.chars().count() <= MAX_FMT);
|
||||
let mut spec = ChartSpec::sample(ChartType::Column);
|
||||
spec.val_axis.fmt = Some(fmt.clone());
|
||||
let spec = spec.sanitized();
|
||||
assert_eq!(spec.val_axis.fmt.as_deref(), Some(fmt.as_str()));
|
||||
assert_eq!(spec_of(&parse(&spec)).as_ref(), Some(&spec), "{} chars", fmt.chars().count());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_chart_with_more_than_the_model_stays_read_only() {
|
||||
let spec = ChartSpec::sample(ChartType::Column);
|
||||
|
||||
@@ -311,7 +311,7 @@ pub(super) fn axis(a: Option<&El>) -> Axis {
|
||||
.child("c:numFmt")
|
||||
.filter(|f| f.attr("sourceLinked") != Some("1"))
|
||||
.and_then(|f| f.attr("formatCode"))
|
||||
.filter(|f| f.len() <= MAX_FORMAT_CODE)
|
||||
.filter(|f| f.chars().count() <= craft_wordmodel::chart::MAX_FMT)
|
||||
.map(str::to_string),
|
||||
title: a.child("c:title").and_then(title_text),
|
||||
labels: a.child("c:tickLblPos").and_then(|p| p.attr("val")) != Some("none"),
|
||||
|
||||
@@ -386,9 +386,13 @@ fn axis_format_code_length_is_capped() {
|
||||
let x = format!(r#"<c:valAx {NS}><c:numFmt formatCode="{code}" sourceLinked="0"/></c:valAx>"#);
|
||||
axis(Some(&crate::xml::parse(x.as_bytes()).unwrap())).fmt
|
||||
};
|
||||
let ok = format!("{}0", "x".repeat(254));
|
||||
use craft_wordmodel::chart::MAX_FMT;
|
||||
// The limit is the model's, counted in characters (a CJK character is one).
|
||||
let ok = format!("{}0", "x".repeat(MAX_FMT - 1));
|
||||
assert_eq!(fmt(&ok), Some(ok.clone()));
|
||||
assert_eq!(fmt(&format!("{}0", "x".repeat(300))), None);
|
||||
let cjk = format!("{}0", "\u{5143}".repeat(MAX_FMT - 1));
|
||||
assert_eq!(fmt(&cjk), Some(cjk.clone()));
|
||||
assert_eq!(fmt(&format!("{}0", "x".repeat(MAX_FMT))), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user