Make WordPress Core

Opened 5 years ago

Last modified 4 years ago

#49955 new defect (bug)

Shortcode escaping not correctly handled when followed by enclosing shortcodes

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

Description

There are some special situations when shortcode escaping is not correctly handled.

This code will reproduce the error:

<?php
function ucase_shortcode($atts, $content) {
    return strtoupper($content);
}
add_shortcode('ucase', 'ucase_shortcode');

The following content:

This [[ucase]] shortcode [ucase]demonstrates[/ucase] the usage of enclosing shortcodes.

will produce this output:

This [] SHORTCODE [UCASE]DEMONSTRATES the usage of enclosing shortcodes.

but this would be expected:

This [ucase] shortcode DEMONSTRATES the usage of enclosing shortcodes.

It seems the escaped shortcode does not detect its ending double bracket, but just moves on until it finds an enclosing shortcode of same type.

Change History (2)

#1 @cfinke
4 years ago

I've confirmed that I see this behavior as well with the current trunk code by adding this testcase to Tests_Shortcode

	function test_ticket_49955() {
		add_shortcode( 'ucase', function ( $atts, $content ) {
			return strtoupper( $content );
		} );
			
		$out = do_shortcode( 'This [[ucase]] shortcode [ucase]demonstrates[/ucase] the usage of enclosing shortcodes.' );
		
		$this->assertEquals( 'This [ucase] shortcode DEMONSTRATES the usage of enclosing shortcodes.', $out );
	}

#2 @cfinke
4 years ago

#50683 is a potential fix for this and other issues, if you'd like to review the patch there and give feedback.

Note: See TracTickets for help on using tickets.