WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 3 weeks ago

#49955 new defect (bug)

Shortcode escaping not correctly handled when followed by enclosing shortcodes

Reported by: 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
3 weeks 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
3 weeks 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.