[wp-trac] [WordPress Trac] #47863: Fix odd, unexpected output from shortcode_parse_attts

WordPress Trac noreply at wordpress.org
Mon Aug 12 00:16:18 UTC 2019


#47863: Fix odd, unexpected output from shortcode_parse_attts
--------------------------------------+-----------------------------
 Reporter:  mauteri                   |       Owner:  SergeyBiryukov
     Type:  defect (bug)              |      Status:  reviewing
 Priority:  normal                    |   Milestone:  5.3
Component:  Shortcodes                |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------
Changes (by birgire):

 * keywords:  has-patch => has-patch has-unit-tests


Comment:

 Thanks @SergeyBiryukov

 Reading the docblock's description of {{{shortcode_parse_atts()}}},

 https://core.trac.wordpress.org/browser/tags/5.2/src/wp-
 includes/shortcodes.php#L483


 it seems to indicate that this should be supported, e.g.:

 > * Retrieve all attributes from the shortcodes tag.

 So at a first glance, it seems like a good enhancement.

 Maybe the docblock could be enhanced as well, e.g. adding a descripton to
 the {{{* @param string $text}}} part?

 Just curious about the {{{\w+}}} choice, as I noticed that in
 {{{get_shortcode_atts_regex()}}}

 https://core.trac.wordpress.org/browser/tags/5.2/src/wp-
 includes/shortcodes.php#L480

 we have {{{[\w-]+}}}. I guess these should match?


 I didn't find any explicit tests for {{{shortcode_parse_atts()}}}, so it
 seems good to add them.

 In the description of {{{shortcode_parse_atts()}}} we have:

 {{{
 * @return array|string List of attribute values.
 *                      Returns empty array if trim( $text ) == '""'.
 *                      Returns empty string if trim( $text ) == ''.
 *                      All other matches are checked for not empty().

 }}}

 so I would suggest adding these test cases to the data provider in
 [attachment:"47863.patch"].

 And also test cases with {{{-}}} in the shortcode's tag name.

 ps:

 According to https://make.wordpress.org/core/2019/07/12/php-coding-
 standards-changes/

 > Arrays must be declared using long array syntax in WordPress Core.

 so I would assume it applying to the tests as well.

 Then we would need to add a {{{@since 5.3.0}}} in the docblock of the test
 method.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47863#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list