mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
wptexturize() improvements:
* Expand the `wptexturize()` RegEx to include the list of registered shortcodes. * Avoid backtracking after `[` chars by not filtering params in registered shortcodes. This will cause escaped shortcodes and their params to become texturized if not registered. * Registered shortcode params will never be texturized, even when escaped. * Move all tests involving unregistered shortcodes to a new and improved unit. * Update one test involving HTML within shortcode params. Props miqrogroove. See #29557. git-svn-id: https://develop.svn.wordpress.org/trunk@29748 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -11,7 +11,6 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
|
||||
|
||||
function test_disable() {
|
||||
$this->assertEquals('<pre>---</pre>', wptexturize('<pre>---</pre>'));
|
||||
$this->assertEquals('[a]a–b[code]---[/code]a–b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]'));
|
||||
$this->assertEquals('<pre><code></code>--</pre>', wptexturize('<pre><code></code>--</pre>'));
|
||||
|
||||
$this->assertEquals( '<code>---</code>', wptexturize( '<code>---</code>' ) );
|
||||
@@ -1209,28 +1208,20 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
|
||||
'[gallery ...]]',
|
||||
),
|
||||
array(
|
||||
'[/...]', // This would actually be ignored by the shortcode system. The decision to not texturize it is intentional, if not correct.
|
||||
'[/...]',
|
||||
'[/gallery ...]', // This would actually be ignored by the shortcode system. The decision to not texturize it is intentional, if not correct.
|
||||
'[/gallery ...]',
|
||||
),
|
||||
array(
|
||||
'[...]...[/...]', // These are potentially usable shortcodes.
|
||||
'[...]…[/...]',
|
||||
'[…]…[/…]',
|
||||
),
|
||||
array(
|
||||
'[[...]]...[[/...]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode.
|
||||
'[[...]]…[[/...]]',
|
||||
'[[gallery]]...[[/gallery]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode.
|
||||
'[[gallery]]…[[/gallery]]',
|
||||
),
|
||||
array(
|
||||
'[[[...]]]...[[[/...]]]', // Again, shortcode parsing matches, but only the [[...] and [/...]] parts.
|
||||
'[[[...]]]…[[[/...]]]',
|
||||
),
|
||||
array(
|
||||
'[[code]...[/code]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[code] is ambiguous unless we run the entire shortcode regexp.
|
||||
'[[code]…[/code]…',
|
||||
),
|
||||
array(
|
||||
'[code]...[/code]]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [/code]] is ambiguous unless we run the entire shortcode regexp.
|
||||
'[code]...[/code]]...', // This test would not pass in 3.9 because the extra brace was always ignored by texturize.
|
||||
'[[[gallery]]]...[[[/gallery]]]', // Again, shortcode parsing matches, but only the [[gallery] and [/gallery]] parts.
|
||||
'[[[gallery]]]…[[[/gallery]]]',
|
||||
),
|
||||
array(
|
||||
'[gal>ery ...]',
|
||||
@@ -1345,8 +1336,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
|
||||
'[ but also catches the <b>styled “[quote]” here</b> ]',
|
||||
),
|
||||
array(
|
||||
'[Let\'s get crazy<input>[plugin code="<a href=\'?a[]=100\'>hello</a>"]</input>world]',
|
||||
'[Let’s get crazy<input>[plugin code="<a href=\'?a[]=100\'>hello</a>"]</input>world]',
|
||||
'[Let\'s get crazy<input>[caption code="<a href=\'?a[]=100\'>hello</a>"]</input>world]', // caption shortcode is invalid here because it contains [] chars.
|
||||
'[Let’s get crazy<input>[caption code=”<a href=\'?a[]=100\'>hello</a>“]</input>world]',
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1698,32 +1689,85 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
|
||||
'<code>hello</span>---</span>',
|
||||
),
|
||||
array(
|
||||
'<span>hello[/code]---</span>',
|
||||
'<span>hello[/code]—</span>',
|
||||
'<span><code>hello</code>---</span>',
|
||||
'<span><code>hello</code>—</span>',
|
||||
),
|
||||
array(
|
||||
'[/code]hello<span>---</span>',
|
||||
'[/code]hello<span>—</span>',
|
||||
'<code>hello</code>world<span>---</span>',
|
||||
'<code>hello</code>world<span>—</span>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test disabling shortcode texturization.
|
||||
*
|
||||
* @ticket 29557
|
||||
* @dataProvider data_unregistered_shortcodes
|
||||
*/
|
||||
function test_unregistered_shortcodes( $input, $output ) {
|
||||
add_filter( 'no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1 );
|
||||
|
||||
$output = $this->assertEquals( $output, wptexturize( $input ) );
|
||||
|
||||
remove_filter( 'no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1 );
|
||||
return $output;
|
||||
}
|
||||
|
||||
function filter_shortcodes( $disabled ) {
|
||||
$disabled[] = 'audio';
|
||||
return $disabled;
|
||||
}
|
||||
|
||||
function data_unregistered_shortcodes() {
|
||||
return array(
|
||||
array(
|
||||
'[a]a--b[audio]---[/audio]a--b[/a]',
|
||||
'[a]a–b[audio]---[/audio]a–b[/a]',
|
||||
),
|
||||
array(
|
||||
'[code]hello[/code]---</span>',
|
||||
'[code]hello[/code]—</span>',
|
||||
'[code ...]...[/code]', // code is not a registered shortcode.
|
||||
'[code …]…[/code]',
|
||||
),
|
||||
array(
|
||||
'<span>hello</span>---[code]',
|
||||
'<span>hello</span>—[code]',
|
||||
'[hello ...]...[/hello]', // hello is not a registered shortcode.
|
||||
'[hello …]…[/hello]',
|
||||
),
|
||||
array(
|
||||
'<span>hello[code]---</span>',
|
||||
'<span>hello[code]---</span>',
|
||||
'[[audio]...[/audio]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[audio] is ambiguous unless we run the entire shortcode regexp.
|
||||
'[[audio]…[/audio]…',
|
||||
),
|
||||
array(
|
||||
'[code]hello<span>---</span>',
|
||||
'[code]hello<span>---</span>',
|
||||
'[audio]...[/audio]]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [/audio]] is ambiguous unless we run the entire shortcode regexp.
|
||||
'[audio]...[/audio]]...', // This test would not pass in 3.9 because the extra brace was always ignored by texturize.
|
||||
),
|
||||
array(
|
||||
'[code]hello</span>---</span>',
|
||||
'[code]hello</span>---</span>',
|
||||
'<span>hello[/audio]---</span>',
|
||||
'<span>hello[/audio]—</span>',
|
||||
),
|
||||
array(
|
||||
'[/audio]hello<span>---</span>',
|
||||
'[/audio]hello<span>—</span>',
|
||||
),
|
||||
array(
|
||||
'[audio]hello[/audio]---</span>',
|
||||
'[audio]hello[/audio]—</span>',
|
||||
),
|
||||
array(
|
||||
'<span>hello</span>---[audio]',
|
||||
'<span>hello</span>—[audio]',
|
||||
),
|
||||
array(
|
||||
'<span>hello[audio]---</span>',
|
||||
'<span>hello[audio]---</span>',
|
||||
),
|
||||
array(
|
||||
'[audio]hello<span>---</span>',
|
||||
'[audio]hello<span>---</span>',
|
||||
),
|
||||
array(
|
||||
'[audio]hello</span>---</span>',
|
||||
'[audio]hello</span>---</span>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user