fix(pptx): coerce None shape/notes text to '' before concatenation (#1808)#1862
Open
haosenwang1018 wants to merge 1 commit into
Open
fix(pptx): coerce None shape/notes text to '' before concatenation (#1808)#1862haosenwang1018 wants to merge 1 commit into
haosenwang1018 wants to merge 1 commit into
Conversation
Closes microsoft#1808 ``PptxConverter.convert`` performed unguarded ``+`` concatenation on ``shape.text`` and ``notes_frame.text``. python-pptx returns ``None`` for either value when a text frame has a run with no ``<a:t>`` child, or when third-party generators emit chart/SmartArt elements whose title text is ``None``. A single such shape failed the entire conversion with:: PptxConverter threw TypeError with message: can only concatenate str (not "NoneType") to str Coerce ``shape.text`` and ``notes_frame.text`` to ``""`` before appending. The behavior for normal (non-None) decks is unchanged — ``"" or None`` would have been the same as the original ``None`` value on the path; the only difference is that ``None`` no longer raises. Tests cover both call sites (body shape text and notes-slide text) plus a regression guard that normal decks still convert as before. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@haosenwang1018 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Closes #1808
Root cause
PptxConverter.convertperformed unguarded+concatenation onshape.textandnotes_frame.text. python-pptx returnsNonefor either value when:<a:t>childNoneA single such shape failed the entire .pptx conversion with
TypeError: can only concatenate str (not "NoneType") to str.Fix
Coerce
shape.text/notes_frame.textto""before concatenation at both call sites in_pptx_converter.py. Normal decks see no behavior change — only theNonecase is different (was: raise; now: empty contribution).This is the exact code shape the issue body proposed.
Tests
test_pptx_with_none_shape_text_does_not_crash— uses the issue body's monkey-patch trick to makeTextFrame.textreturnNonefor a specific value, then converts a deck containing it. Pre-fix raisesTypeError, post-fix completes and the title is preserved.test_pptx_with_none_notes_text_does_not_crash— covers the second call site (notes slide).test_pptx_normal_text_still_converts— regression guard for the happy path.