#59249 closed defect (bug) (fixed)
shortcode_parse_atts() result for no attributes does not match the documentation
Reported by: | SergeyBiryukov | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 6.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Shortcodes | Keywords: | has-patch has-testing-info has-unit-tests commit needs-dev-note |
Focuses: | Cc: |
Description
Background: #59206.
The shortcode_parse_atts()
documentation says:
* @return array|string Array of attribute values keyed by attribute name. * Returns empty array if there are no attributes. * Returns the original arguments string if it cannot be parsed.
The middle part (empty array if there are no attributes) appears to be incorrect. In my testing, the function returns an empty string in that case.
Do we want to update the results to match the documentation, or just correct the documentation?
Some history:
Change History (21)
#2
@
14 months ago
From a logical point, it is better when the return value is consistent. In many cases change of return value can introduce a regression or need of change to plugins/themes, but because of each returning in an array attribute needs to be checked before usage anyway, I cannot imagine a regression in this case.
So, I am suggesting to return empty array if there are no actual attributes.
This ticket was mentioned in PR #5367 on WordPress/wordpress-develop by @nicolefurlan.
14 months ago
#3
- Keywords has-patch added
- Adds conditional to
shortcode_parse_atts()
to return an empty array if there are no attributes on the shortcode. - Reorders
@return
options onshortcode_parse_atts()
doc block to reflect order of if statement for clarity.
Trac ticket: https://core.trac.wordpress.org/ticket/59249
#4
@
14 months ago
- Owner set to nicolefurlan
- Status changed from new to assigned
I've added a PR with the change that @oglekler suggested 👍
#5
@
14 months ago
Testing Instructions
To test this change, we should verify that shortcodes continue to generate the appropriate markup on the frontend both with and without attributes.
Steps to Test
- Create a post or page and add shortcodes with and without attributes. WordPress has several built-in shortcodes that we can use for testing: https://developer.wordpress.org/plugins/shortcodes/#built-in-shortcodes
e.g.
[caption id="id" caption_id="caption_id" align="aligncenter" width="300" caption="caption text" class="class"]Caption with attributes[/caption] [caption]Caption without attributes[/caption]
Expected Results
- Shortcodes should continue to generate the appropriate markup on the frontend both with and without attributes.
This ticket was mentioned in Slack in #core by oglekler. View the logs.
14 months ago
#11
@
14 months ago
The patch here still does not grant consistent output and adds an additional unnecessary if
check when we can just do this:
https://core.trac.wordpress.org/ticket/59613
https://github.com/WordPress/wordpress-develop/pull/5480
There is no reason why we should return a string in any case. It disrupts dependant code, which then needs to "juggle" whether or not it receives expected input.
Please see the linked trac (and pr) which has been marked as duplicate.
The patch committed here would nor resolve the issues this problem causes in dependant code.
#12
@
14 months ago
- Milestone changed from 6.4 to 6.5
@SergeyBiryukov or @swissspidy do you have any thoughts on #comment:11?
@aaroncampbell pinging you as well as the component maintainer.
I'm happy to update the PR whenever we can reach a consensus.
Since this patch possibly needs an update and definitely still needs testing, I'm moving it to 6.5.
#13
@
14 months ago
- Keywords needs-unit-tests added
A simplified patch like https://github.com/WordPress/wordpress-develop/pull/5480 looks good. Just needs correct docblock adjustments and ideally unit tests.
This ticket was mentioned in PR #6015 on WordPress/wordpress-develop by @swissspidy.
10 months ago
#15
- Keywords has-unit-tests added; needs-unit-tests removed
I don't see harm in always returning an empty array here.
Reverts https://core.trac.wordpress.org/changeset/56488 because it's no longer needed.
Trac ticket: https://core.trac.wordpress.org/ticket/59249
#16
@
10 months ago
- Keywords commit added; 2nd-opinion needs-testing removed
- Owner changed from nicolefurlan to swissspidy
@swissspidy commented on PR #6015:
10 months ago
#18
Committed in https://core.trac.wordpress.org/changeset/57597
@swissspidy commented on PR #5367:
10 months ago
#19
Committed in https://core.trac.wordpress.org/changeset/57597
Correct, it's an empty string. For more: #26927