Skip to content

xlsx: escape shape font typeface attribute (#2170) - #2196

Merged
FredApps merged 5 commits into
storytold:mainfrom
Higgs32584:fix/2170-shape-font-attr-escape
Nov 11, 2026
Merged

FredApps merged 5 commits into
storytold:mainfrom
Higgs32584:fix/2170-shape-font-attr-escape

Conversation

@Higgs32584

@Higgs32584 Higgs32584 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2170.

The shape text writer put the font name into <a:latin typeface="…"/> with the element-text escaper esc, which doesn't escape ". A font name containing a quote could close the attribute and inject new attributes into the saved drawing XML.

  • crates/xlsx/src/drawing.rs: esc(font) → esc_attr(font).
  • Audited the other attribute writes in drawing.rs, drawing/ink.rs and theme.rs: they already use esc_attr or write fixed/numeric values. Remaining esc( calls in the crate write element text.

Tests

  • New tests::shape_text_rtl::shape_font_typeface_is_attribute_escaped: font a"b<c&d' injected="x is escaped in the saved XML, no injected attribute appears, and the name round-trips through save and reopen. Passes along with the existing tests in that file.
  • Not run locally (slow machine): cargo xtask ci, clippy, wasm, fuzzers — relying on CI.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where special characters in shape font names could produce invalid spreadsheet XML.
    • Font names containing quotation marks, angle brackets, or ampersands are now safely escaped and preserved when saving and reopening workbooks.
    • Shape text retains its intended font and content, and special characters are no longer interpreted as additional XML attributes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 94eed2b and 088b43b.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Shape font typefaces now use XML attribute escaping in drawing XML. A regression test checks special-character escaping, rejects injected attributes, and verifies the font and text after saving and reopening a workbook.

Changes: Shape font XML

Layer / File(s) Summary
Attribute escaping and regression test
crates/xlsx/src/drawing.rs, crates/xlsx/src/tests/shape_text_rtl.rs
run_props now uses attribute escaping for the font typeface. The test checks special characters, absence of injected attributes, and preservation of the font and text after save and reopen.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • #2170 — The change addresses the shape font attribute escaping defect described in this issue.
  • #2290 — The change addresses the tracked shape font typeface item; the other findings in the tracking issue are not changed.

Suggested reviewers: vangel76

Merge Risk: Minimal · previous review 94eed

No actionable merge-blocking risk remains in the reviewed change.

Architecture risk: Low · up to 79342

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/xlsx/src/tests/shape_text_rtl.rs: Added shape_font_typeface_is_attribute_escaped, which verifies special characters in a shape font typeface are escaped in drawing XML, injected attributes are absent, and the font and text survive XLSX serialization and reopening.
  • observed — Modified behavior in crates/xlsx/src/drawing.rs: run_props now uses attribute escaping for the font typeface value instead of text escaping.
Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: shape font typeface serialization in the xlsx crate now uses attribute escaping (esc_attr) instead of text-node escaping (esc). The raw summary confirms run_props in d…
Linked Issues check Passed Issue #2170 has two coding requirements: (1) write the shape font typeface with an attribute escaper, and (2) add a round-trip test for a font name with special characters. The whole-PR diff (merge …
Out of Scope Changes check Passed The whole-PR diff has two changed files. crates/xlsx/src/drawing.rs changes one line, the shape font typeface writer. crates/xlsx/src/tests/shape_text_rtl.rs adds one regression test for that wr…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the main change: shape font typeface serialization in the xlsx crate now uses attribute escaping (esc_attr) instead of text-node escaping (esc). The raw summary confirms run_props in drawing.rs makes this change and a regression test was added. The title's '(#2170)' refers to the linked issue, which describes the same XML attribute injection problem. The title is specific and accurate, so it passes.

Full details: Linked Issues check

Explanation

Issue #2170 has two coding requirements: (1) write the shape font typeface with an attribute escaper, and (2) add a round-trip test for a font name with special characters. The whole-PR diff (merge base 92cdc2a to head 94eed2b) changes one line in crates/xlsx/src/drawing.rs, in run_props. It changes esc(font) to esc_attr(font). At head, esc_attr in crates/xlsx/src/xml.rs maps " to &amp;quot;, which esc does not do. drawing.rs already imports esc_attr at head, so the change compiles without an import change. The new test shape_font_typeface_is_attribute_escaped in crates/xlsx/src/tests/shape_text_rtl.rs uses the font a"b&lt;c&amp;d' injected="x. It asserts that the saved XML contains &lt;a:latin typeface="a&amp;quot;b&amp;lt;c&amp;amp;d, that no injected="x" attribute appears, and that the font and the text hi survive write_xlsx and read_xlsx. The read path decodes &amp;quot; in attribute values, so the round-trip assertion matches the code. Both requirements of #2170 are met in code. The test was not run during this review. Its result rests on source reading only.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff has two changed files. crates/xlsx/src/drawing.rs changes one line, the shape font typeface writer. crates/xlsx/src/tests/shape_text_rtl.rs adds one regression test for that writer, with a doc comment that cites #2170. Both changes match the #2170 objective. The PR description says other attribute writes in drawing.rs, drawing/ink.rs and theme.rs were audited and need no change. That audit adds no code to this PR, so it does not affect scope. No unrelated change appears in the diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c31e4af and 94eed2b.

Files selected for processing: 2

  • crates/xlsx/src/drawing.rs
  • crates/xlsx/src/tests/shape_text_rtl.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the whole change. The shape font typeface in crates/xlsx/src/drawing.rs run_props is now written with esc_attr instead of esc, so a quote, < or & in the font name cannot end the typeface attribute early or add attributes. The new test writes a font name holding ", <, & and an injected injected="x", checks the escaped output and that no attribute is injected, then reopens the file and gets the same font name back.

cargo xtask ci (https://github.com/storytold/gridcraft/actions/runs/39698735205/job/119562435586) and the SonarCloud scan (https://github.com/storytold/gridcraft/actions/runs/39698735382/job/119562436480) pass at this head.

@Harrison-Booth

Copy link
Copy Markdown
Contributor

Review notes (not a formal review) on head 4ab3eda.

Checked

  • One-line fix in crates/xlsx/src/drawing.rs (~l.474): the shape font name goes through esc_attr instead of esc, which does not escape ". esc_attr is already imported there (used for the picture alt text at ~l.334). The new test shape_font_typeface_is_attribute_escaped (crates/xlsx/src/tests/shape_text_rtl.rs, ~l.87) writes a"b<c&d' injected="x, checks the escaped form, that no attribute appears, and that the name round-trips.
  • I grepped crates/xlsx/src on current main for other attribute writes that use esc(: the font typeface was the only one (the others are element text).
  • CI is green. No assets or third-party code.

Not checked

  • I did not run the Rust tests, and did not open a saved file with such a font name in real Excel; an odd name like this is not something Excel's UI offers, so there is no Excel behaviour to compare.

Looks ready for a maintainer from my side.

@FredApps
FredApps merged commit 0220743 into storytold:main Nov 11, 2026
6 checks passed
@FredApps

Copy link
Copy Markdown
Contributor

Merged as 0220743. Updated the branch with main 0fed26a and rechecked the complete two-file diff; the approved patch is unchanged. Fresh CI passed all 10 gates, including the shape-font attribute escaping and round-trip regression: 3,744 tests passed, 4 skipped. No unresolved review threads. Validation used source inspection and hosted CI; no separate local build was run.

@Higgs32584
Higgs32584 deleted the fix/2170-shape-font-attr-escape branch November 11, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XML attribute injection in shape font typeface

3 participants