Skip to content

Blocks: Don't return null for string value #1766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 5, 2025

Conversation

obenland
Copy link
Member

@obenland obenland commented Jun 4, 2025

Fixes a bug where updating meta values ends up comparing different data types and failing.

Proposed changes:

  • Always save a string for activitypub_content_warning, regardless if it's empty or not.

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

This is better tested on a site where the Jetpack plugin is installed, connected to WordPress.com, and where you've toggled the Newsletter feature on. All WordPress.com simple sites satisfy those requirements.

  1. Go to Posts > Add New
  2. Write a new post with some ActivityPub content, such as a Federated reply block with any ActivityPub-compatible content like https://mastodon.social/@pfefferle/114502331086451476.
  3. Hit Publish
  4. Before to confirm publication, check the Newsletter panel, and change the value to "Post only".
  5. Hit Publish.
    • The post should be published with no errors.
    • You should see a Create event in the outbox.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Avoid type mismatch when updating activitypub_content_warning meta values.

@obenland obenland self-assigned this Jun 4, 2025
@github-actions github-actions bot added [Focus] Editor Changes to the ActivityPub experience in the block editor [Status] In Progress labels Jun 4, 2025
@obenland obenland marked this pull request as ready for review June 5, 2025 13:46
@obenland obenland requested review from pfefferle, Copilot and jeherve and removed request for pfefferle June 5, 2025 13:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Ensure the activitypub_content_warning post meta always stores a string by switching from a custom callback that could return null to the built-in sanitize_text_field.

  • Removed anonymous sanitize callback returning null for empty values
  • Switched to sanitize_text_field for consistent string output
Comments suppressed due to low confidence (1)

includes/class-blocks.php:46

  • Add or update unit tests to confirm that the sanitize callback returns an empty string (rather than null) when no warning text is provided.
'sanitize_callback' => 'sanitize_text_field',

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This fixes the issue for me. 🚢

@obenland obenland merged commit e1a9a92 into trunk Jun 5, 2025
11 checks passed
@obenland obenland deleted the fix/content-warning-sanitization branch June 5, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Editor Changes to the ActivityPub experience in the block editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants