Make WordPress Core

Opened 20 months ago

Closed 7 months ago

Last modified 3 months ago

#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: vpelss's profile vpelss Owned by:
Milestone: 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 (7)

#1 @sabernhardt
20 months ago

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

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

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

#5 @vpelss
7 months ago

I am not sure if these are 'tickets' and can be closed, but you can close this one. It seems that it was actually browser behaviour that is causing this.

Value= otherAttrib="blah" will not equate to value otherAttrib="blah"

#6 @vpelss
7 months ago

  • Resolution set to invalid
  • Status changed from new to closed

#7 @peterwilsoncc
3 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.