Repository navigation
Block Library: Fix incorrect attributes definitions - #36264
Merged
Merged
Conversation
The `templateLock` attribute is mixed between boolean and string. Setting the type as string introduces an regression that will remove `false` on save. The original PR (#36140) tried to fix a validation issue reported in #35902 The schema error is incorrect. The attribute definition is required to have either a `type` or an `enum`.
8 tasks done
Member
|
Good catch. It's a bit surprising to see boolean and string values mixed for this attribute but the proposed fix makes sense 👍🏻 |
gziolo
approved these changes
Nov 8, 2021
gziolo
left a comment
Member
There was a problem hiding this comment.
I tested it with the following unit test:
diff --git a/packages/blocks/src/api/parser/test/get-block-attributes.js b/packages/blocks/src/api/parser/test/get-block-attributes.js
index 727f052a54..7b48db67fd 100644
--- a/packages/blocks/src/api/parser/test/get-block-attributes.js
+++ b/packages/blocks/src/api/parser/test/get-block-attributes.js
@@ -222,6 +222,22 @@ describe( 'attributes parsing', () => {
expect( value ).toBe( 10 );
} );
+ it( 'should return the comment attribute value when using multiple types', () => {
+ const value = getBlockAttribute(
+ 'templateLock',
+ {
+ type: [ 'string', 'boolean' ],
+ enum: [ 'all', 'insert', false ],
+ },
+ '',
+ {
+ templateLock: false,
+ }
+ );
+
+ expect( value ).toBe( false );
+ } );
+
it( 'should reject type-invalid value, with default', () => {
const value = getBlockAttribute(
'number',We could add it to the test coverage to ensure that the behavior never regresses.
7 tasks
Member
Author
|
Yes, I'll add that unit test 👍 |
|
Size Change: +2.72 kB (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
andrewserong
approved these changes
Nov 10, 2021
andrewserong
left a comment
Contributor
There was a problem hiding this comment.
This LGTM, too. Let's merge this in and cherry pick into the 11.9 release.
noisysocks
pushed a commit
that referenced
this pull request
Nov 10, 2021
* Revert "Block Library: Fix incorrect attributes definitions #36140" The `templateLock` attribute is mixed between boolean and string. Setting the type as string introduces an regression that will remove `false` on save. The original PR (#36140) tried to fix a validation issue reported in #35902 The schema error is incorrect. The attribute definition is required to have either a `type` or an `enum`. * Spesify type as string or boolean * Add unit test
andrewserong
pushed a commit
that referenced
this pull request
Nov 10, 2021
* Revert "Block Library: Fix incorrect attributes definitions #36140" The `templateLock` attribute is mixed between boolean and string. Setting the type as string introduces an regression that will remove `false` on save. The original PR (#36140) tried to fix a validation issue reported in #35902 The schema error is incorrect. The attribute definition is required to have either a `type` or an `enum`. * Spesify type as string or boolean * Add unit test
Contributor
|
Cherry picked into the Gutenberg 11.9 release in: e8ce5d6 |
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.
Description
The
templateLockattribute is mixed between boolean and string. Setting the type as string introduces an regression that will removefalseon save. Addbooleanas a valid type.How has this been tested?
By inserting a block that support templateLock with
falseand confirmed the saved content is correct with the PR applied.Screenshots
Screencast of the error:

Types of changes
Bug fix
Checklist:
*.native.jsfiles for terms that need renaming or removal).