#60948 closed defect (bug) (invalid)
shortcodes that return with no value / text will break if shortcode is being used as an attribute value
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 6.5 |
| Component: | Shortcodes | Keywords: | |
| Focuses: | Cc: |
Description (last modified by )
shortcodes that return with no value / text will break if shortcode is being used as an attribute value. Shortcode works in this scenario if there is text / value returned.
eg:
<input type="email" class="regular-text ltr form-required" id="imok_contact_email_1" name="imok_contact_email_1" value=[imok_contact_email_1] title="Please enter a valid email address." required>
if [imok_contact_email_1] returns an empty string, the result of the input tag above is:
<input type="email" class="regular-text ltr form-required" id="imok_contact_email_1" name="imok_contact_email_1" value= title="Please enter a valid email address." required>
This mangles the html output and the attribute for value becomes:
value="title="Please"
Placing the shortcode between quotes fails for the following reason:
See: #34983
Offending code is in shortcodes.php
function do_shortcodes_in_html_tags
line:
if ( '' !== trim( $new_attr ) ) {
I am not sure why that line exists.
Change History (7)
#2
@
20 months ago
The test for
'' !==
is the issue I think.
Surely there are valid cases when a shortcode should be allowed to return no text.
When that occurs in a tag's attribute, the code can't cope.
Thus:
value="title="Please"
in my example.
#3
@
20 months ago
I hope this is clearer in describing what the code is doing.
Cases:
Will not replace shortcode
<input type="email" value="[imok_contact_email_1]" title="Please enter a valid email address.">
Will replace shortcode if shortcode returns a value. Will mangle html output (uses the next attribute name and part of value if any) if shortcode returns no value.
<input type="email" value=[imok_contact_email_1] title="Please enter a valid email address.">
#4
@
7 months ago
I am assuming that whatever https://core.trac.wordpress.org/ticket/60948 fixed is worth this bug? The shortest way I can explain that if a shortcode used as a tag's attribute value returns nothing, it mangles the attribute value by sucking up the next attribute title.
Sure not a lot of code might do that, but the code is broken in that respect.
The trimming was added in [33600] / #33259.