Opened 16 months ago
Last modified 3 months ago
#59509 new defect (bug)
Shortcode attributes named 0 are ignored
Reported by: | ourous | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.3.1 |
Component: | Shortcodes | Keywords: | needs-unit-tests has-patch |
Focuses: | Cc: |
Description
Shortcode attributes in the form 0=...
are not picked up during parsing.
This is because the parser checks for an empty name with empty(..)
, which also returns true for the string '0'
.
Change History (4)
This ticket was mentioned in PR #7633 on WordPress/wordpress-develop by @debarghyabanerjee.
3 months ago
#2
- Keywords has-patch added; needs-patch removed
Trac Ticket: Core-59509
## Overview
- This pull request addresses an issue in the shortcode_parse_atts() function, where attributes in the form of numeric keys (e.g., 0=value) were not being parsed correctly. The existing implementation used empty() to check for attribute names, which incorrectly evaluated numeric strings as empty, leading to the omission of such attributes.
## Changes Made
- Updated the parsing logic in shortcode_parse_atts() to use isset() instead of empty() for checking the presence of attribute names. This change ensures that numeric keys are properly recognized and included in the parsed attributes
array.
## Rationale
- The ability to parse numeric attribute names is important for shortcodes that may use them as valid parameters. This modification improves the robustness of the shortcode parsing functionality, making it more consistent with expected usage scenarios.
## Updated Code Snippet:
if ( isset( $m[1] ) && '' !== $m[1] ) { $atts[ strtolower( $m[1] ) ] = stripcslashes( $m[2] ); }
## Testing:
- Verified that existing shortcode functionality remains unaffected.
## Impact
- This change is backward-compatible and only affects the internal logic of attribute parsing. It enhances the flexibility of shortcode attributes without breaking existing implementations.
## Documentation
- The documentation for shortcode_parse_atts() has been reviewed and remains accurate.
@debarghyabanerjee commented on PR #7633:
3 months ago
#3
Hi @SergeyBiryukov , can you please take a look into this PR. Thanks.
Note: See
TracTickets for help on using
tickets.
Hi there, welcome to WordPress Trac! Thanks for the report, I was able to reproduce the issue.
Looks like this happens because the
shortcode_parse_atts()
function has some checks like! empty( $m[1] )
, which should perhaps be replaced with'' !== $m[1]
.