Skip to content

Bug 919: Ensure clearText() produces valid XML by adding default empty paragraph - #1192

Open
waterWang wants to merge 1 commit into
apache:trunkfrom
waterWang:trunk
Open

Bug 919: Ensure clearText() produces valid XML by adding default empty paragraph#1192
waterWang wants to merge 1 commit into
apache:trunkfrom
waterWang:trunk

Conversation

@waterWang

Copy link
Copy Markdown

Description

When clearText() is called on a text shape (e.g., XSLFTextBox), it removes all paragraphs from the CTTextBody. If the shape is saved without adding new content, the resulting OOXML document is invalid because the OOXML spec requires at least one paragraph in a text body.

Fix

After clearing all paragraphs, add a default empty paragraph to ensure the XML remains valid. This allows clearText() to be used safely without immediately adding new content.

Test

Added testClearTextWithEmptyParagraph() that:

  1. Creates a slide with a text box
  2. Calls clearText()
  3. Saves and re-reads the presentation
  4. Verifies the shape has at least one empty paragraph
  5. Verifies the text is empty string

Fixes #919

…y paragraph

When clearText() is called on a text shape, it removes all paragraphs
from the CTTextBody, resulting in an invalid OOXML document. This fix
adds a default empty paragraph after clearing to ensure the XML remains
valid even when no new content is added before saving.

Fixes apache#919
@pjfanning

Copy link
Copy Markdown
Member

#1190 is linked to that issue too. Review 1190 and tell me why this is better.

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.

BUG: Shape with empty paragraph & textrun generates invalid XML

2 participants