Conversation
…ns unparsers Port of the 1.x fix (#4059) for issue #4416. When a Saving listener reads $post->content and the content attribute is null (stored as such when an empty string is submitted), PHP would throw a TypeError because the getter and formatter methods only accepted non-nullable strings. Changes: - HasFormattedContent::getContentAttribute: string → ?string, guard null - HasFormattedContent::getParsedContentAttribute: string → ?string - HasFormattedContent::formatContent: early return '' if content is empty - Formatter::unparse: string → ?string, guard null - UnparsePostMentions/UnparseTagMentions/UnparseUserMentions: same guard - UpdateMentionsMetadataWhenVisible: guard null parsed_content before passing to Utils::getAttributeValues() The 2.x fix covers more of the call chain than 1.x because the PATCH response serialises contentHtml (calling formatContent/render), which 1.x never hit since validation rejected empty content before saving. Fixes #4416 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
Port of the 1.x fix (#4059) for issue #4416.
When a
Savinglistener reads$post->contentand the content attribute isnull(stored as such when an empty string is submitted viasetContentAttribute), PHP throws aTypeErrorbecause the getter and formatter methods only accepted non-nullable strings.The 2.x fix covers more of the call chain than 1.x because the
PATCHresponse serialisescontentHtml(callingformatContent→render), which 1.x never hit since validation rejected empty content before saving.Files changed:
HasFormattedContent::getContentAttribute—string → ?string, null guardHasFormattedContent::getParsedContentAttribute—string → ?stringHasFormattedContent::formatContent— early return''if content is empty/nullFormatter::unparse—string → ?string, null guardUnparsePostMentions/UnparseTagMentions/UnparseUserMentions—?string+ null guard on__invokeUpdateMentionsMetadataWhenVisible— null guard onparsed_contentbeforeUtils::getAttributeValues()Fixes #4416
Test plan
CreatePostWithEmptyContentTest,EditPostWithEmptyContentTestSavinglistener that reads$event->post->content, submit a post with empty content — must not 500🤖 Generated with Claude Code