dbunner2 opened a new pull request, #1190: URL: https://github.com/apache/poi/pull/1190
XSLFTextShape.clearText() currently removes every paragraph from a text body, leaving zero <a:p> elements. Since the OOXML schema requires at least one paragraph, PowerPoint opens presentations saved after a clearText() call in repair mode. This change brings clearText() in line with how setText() already behaves: instead of removing every paragraph, it keeps the first paragraph and clears its contents. That preserves a valid text body while still removing all text. Making this change exposed two existing bugs that clearText() had never hit before: 1. XSLFTextParagraph.clearButKeepProperties() removed field elements (<a:fld>, such as slide number or date placeholders) before reading the last run's formatting. If the last run was a field, this resulted in an XmlValueDisconnectedException. It also used _runs.size() to determine how many <a:r> elements to remove, even though _runs includes field runs, which could lead to an IndexOutOfBoundsException. The fix captures the last run's formatting before removing anything and removes only the runs that actually exist in the XML. 2. XSLFTextShape.copy() called clearText() and then appended the source paragraphs, leaving an extra empty paragraph at the beginning and shifting all paragraph indices by one. The fix removes that placeholder paragraph before copying whenever the source contains paragraphs. If the source is empty, the single empty paragraph is left intact, which is already the correct state. I also added a regression test that verifies both the in-memory state and a save/reopen round trip. Fixes [#919.](https://github.com/apache/poi/issues/919) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
