mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-04 09:10:06 +00:00
Shortcodes: prevent registration of invalid shortcode names.
Adds unit tests. Props miqrogroove. Fixes #34090. git-svn-id: https://develop.svn.wordpress.org/trunk@34745 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -539,4 +539,81 @@ EOF;
|
||||
$this->assertTrue( has_shortcode( $content_nested, 'gallery' ) );
|
||||
remove_shortcode( 'foo' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure invalid shortcode names are not allowed.
|
||||
*
|
||||
* @dataProvider data_registration_bad
|
||||
* @expectedIncorrectUsage add_shortcode
|
||||
*/
|
||||
function test_registration_bad( $input, $expected ) {
|
||||
return $this->sub_registration( $input, $expected );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure valid shortcode names are allowed.
|
||||
*
|
||||
* @dataProvider data_registration_good
|
||||
*/
|
||||
function test_registration_good( $input, $expected ) {
|
||||
return $this->sub_registration( $input, $expected );
|
||||
}
|
||||
|
||||
function sub_registration( $input, $expected ) {
|
||||
add_shortcode( $input, '' );
|
||||
$actual = shortcode_exists( $input );
|
||||
$test = $this->assertEquals( $expected, $actual );
|
||||
if ( $actual ) remove_shortcode( $input );
|
||||
return $test;
|
||||
}
|
||||
|
||||
function data_registration_bad() {
|
||||
return array(
|
||||
array(
|
||||
'<html>',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'[shortcode]',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'bad/',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'/bad',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'bad space',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'&',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'',
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function data_registration_good() {
|
||||
return array(
|
||||
array(
|
||||
'good!',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'plain',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'unreserved!#$%()*+,-.;?@^_{|}~chars',
|
||||
true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user