[wp-trac] [WordPress Trac] #60948: shortcodes that return with no value / text will break if shortcode is being used as an attribute value

WordPress Trac noreply at wordpress.org
Sat Apr 6 19:24:00 UTC 2024


#60948: shortcodes that return with no value / text will break if shortcode is
being used as an attribute value
--------------------------+------------------------------
 Reporter:  vpelss        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Shortcodes    |     Version:  6.5
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by sabernhardt):

 * component:  General => Shortcodes


Old description:

> 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: https://core.trac.wordpress.org/ticket/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.

New description:

 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.

--

Comment:

 The trimming was added in [33600] / #33259.

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


More information about the wp-trac mailing list