-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
🦋 Changeset detectedLatest commit: 06a633e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this 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.
I fixed the Sonarqube issue. It was complaining about the |
includes/Blocks/Block.php
Outdated
break; | ||
case 'boolean': | ||
// Only false when value is not null or actually false | ||
$value = ! ( false === $value || is_null( $value ) ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: John Parris <[email protected]>
Description
Bug fix. Parsing boolean block attributes like in CoreVideo always return false.
Fixes: #135
Testing