Skip to content
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

Bug Fix: Parsing boolean block attributes like in CoreVideo always return false. #138

Merged
merged 4 commits into from
Jul 28, 2023

Conversation

theodesp
Copy link
Member

@theodesp theodesp commented Jul 26, 2023

Description

Bug fix. Parsing boolean block attributes like in CoreVideo always return false.

Fixes: #135

Testing

  1. Add a CoreVideo block in a Post and enable some of its checkbox settings for autoplay on the side.
  2. Try to query the block attributes.
  3. The boolean attributes should return the correct checked/unchecked value.

@theodesp theodesp requested a review from a team as a code owner July 26, 2023 12:00
@changeset-bot
Copy link

changeset-bot bot commented Jul 26, 2023

🦋 Changeset detected

Latest commit: 06a633e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@wpengine/wp-graphql-content-blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@theodesp theodesp changed the title MERL-1134 Bug Fix: Parsing boolean block attributes like in CoreVideo always return false. Jul 26, 2023
Copy link
Contributor

@mindctrl mindctrl left a comment

Choose a reason for hiding this comment

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

LGTM. One suggestion to clarify the changelog entry.

.changeset/spicy-tables-cross.md Outdated Show resolved Hide resolved
@mindctrl
Copy link
Contributor

I fixed the Sonarqube issue. It was complaining about the http URLs in the tests.

break;
case 'boolean':
// Only false when value is not null or actually false
$value = ! ( false === $value || is_null( $value ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to be concerned with other falsey values like an empty string?

Im not too familiar with the Block Attribute type validation, but WP is usually horrible at strict booleans.

Copy link
Member Author

@theodesp theodesp Jul 26, 2023

Choose a reason for hiding this comment

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

I think this is specifically targeted for empty strings. An empty string in the context of parsing a boolean attribute like
<video autoplay /> here autoplay="" which according to the HTML spec it's enabled. So in that case we return true. So unless the value is specifically false or null it is considered truthy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Remember that attributes here refer to all block attributes, and just not HTML attributes, so I wouldn't rely on that assumption that the underlying WordPress parser is making that distinction when it comes to the HTML spec.

Any while you've labeled this PR (and the associated test) as specific to CoreVideo, you're actually adding bool handling to all Block attributes plus passing them through helper libraries like DiDom.

It should be easy enough to test and confirm either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the code to handle null returns now. This should work as expected.

mindctrl
mindctrl previously approved these changes Jul 26, 2023
@theodesp theodesp merged commit 748d846 into main Jul 28, 2023
8 checks passed
@theodesp theodesp deleted the MERL-1134 branch July 28, 2023 14:54
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.

CoreVideo returns false for controls regardless of admin setting
4 participants