Make WordPress Core

Opened 8 months ago

Last modified 4 months ago

#60948 new defect (bug)

shortcodes that return with no value / text will break if shortcode is being used as an attribute value

Reported by: vpelss's profile vpelss Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.5
Component: Shortcodes Keywords:
Focuses: Cc:

Description (last modified by sabernhardt)

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 (3)

#1 @sabernhardt
8 months ago

  • Component changed from General to Shortcodes
  • Description modified (diff)

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

#2 @vpelss
8 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 @vpelss
8 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.">


Note: See TracTickets for help on using tickets.