Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#45316 closed defect (bug) (reported-upstream)

parse_blocks returns an empty object in 'attrs' when there are no attributes

Reported by: Chouby Owned by:
Priority: normal Milestone:
Component: Editor Version: 5.0
Severity: normal Keywords:
Cc: Focuses:

Description

According to the inline documentation of WP_Block_Parser, parse_blocks should return arrays not objects, all attributes are arrays. See https://core.trac.wordpress.org/browser/branches/5.0/src/wp-includes/class-wp-block-parser.php#L124

Parsing

<!-- wp:paragraph -->
<p>First paragraph</p>
<!-- /wp:paragraph -->

returns

Array
(
    [0] => Array
        (
            [blockName] => core/paragraph
            [attrs] => stdClass Object
                (
                )

            [innerBlocks] => Array
                (
                )

            [innerHTML] => 
<p>First paragraph</p>

        )

)

If the block has no attribute, [attrs] is an empty object while, according to the documentation, we would expect an empty array.

In other cases, when the block includes attributes or when parsing a free form text, [attrs] is, as expected, an array.

Change History (3)

#1 @swissspidy
8 years ago

Looks like there‘s an open PR for this: https://github.com/WordPress/gutenberg/pull/11434

#2 @matveb
8 years ago

  • Resolutionfixed
  • Status newclosed

Closing as this was addressed upstream.

#3 @ocean90
8 years ago

  • Milestone Awaiting Review
  • Resolution fixedreported-upstream
Note: See TracTickets for help on using tickets.