Shortcode JS: Avoid errors when an escaped shortcode includes a newline between brackets.
props gcorne. props Clorith, jorbin for tests. see #27907, for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@28223 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5907cafe9e
commit
790cb99b27
@ -37,13 +37,13 @@ window.wp = window.wp || {};
|
||||
// If we matched a leading `[`, strip it from the match
|
||||
// and increment the index accordingly.
|
||||
if ( match[1] ) {
|
||||
result.match = result.match.slice( 1 );
|
||||
result.content = result.content.slice( 1 );
|
||||
result.index++;
|
||||
}
|
||||
|
||||
// If we matched a trailing `]`, strip it from the match.
|
||||
if ( match[7] ) {
|
||||
result.match = result.match.slice( 0, -1 );
|
||||
result.content = result.content.slice( 0, -1 );
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -353,4 +353,4 @@ window.wp = window.wp || {};
|
||||
return text + '</' + options.tag + '>';
|
||||
}
|
||||
});
|
||||
}());
|
||||
}());
|
||||
|
@ -57,6 +57,26 @@ jQuery( function() {
|
||||
equal( result, undefined, 'foo shortcode not found when escaped with params' );
|
||||
});
|
||||
|
||||
test( 'next() should find shortcodes that are incorrectly escaped by newlines', function() {
|
||||
var result;
|
||||
|
||||
result = wp.shortcode.next( 'foo', 'this has the [\n[foo]] shortcode' );
|
||||
equal( result.index, 15, 'shortcode found when incorrectly escaping the start of it' );
|
||||
|
||||
result = wp.shortcode.next( 'foo', 'this has the [[foo]\n] shortcode' );
|
||||
equal( result.index, 14, 'shortcode found when incorrectly escaping the end of it' );
|
||||
});
|
||||
|
||||
test( 'next() should still work when there are not equal ammounts of square brackets', function() {
|
||||
var result;
|
||||
|
||||
result = wp.shortcode.next( 'foo', 'this has the [[foo] shortcode' );
|
||||
equal( result.index, 14, 'shortcode found when there are offset square brackets' );
|
||||
|
||||
result = wp.shortcode.next( 'foo', 'this has the [foo]] shortcode' );
|
||||
equal( result.index, 13, 'shortcode found when there are offset square brackets' );
|
||||
});
|
||||
|
||||
test( 'next() should find the second instances of the shortcode when the first one is escaped', function() {
|
||||
var result;
|
||||
|
||||
@ -123,6 +143,16 @@ jQuery( function() {
|
||||
equal( result, 'this bar has the [[foo param="bar"]] shortcode escaped', 'escaped foo with params not replaced but unescaped foo replaced' );
|
||||
});
|
||||
|
||||
test( 'replace() should replace improperly escaped shortcodes that include newlines', function() {
|
||||
var result;
|
||||
|
||||
result = wp.shortcode.replace( 'foo', 'this [foo] has the [[foo param="bar"]\n] shortcode ', shortcodeReplaceCallback );
|
||||
equal( result, 'this bar has the [bar\n] shortcode ', 'escaping with newlines should not actually escape the content' );
|
||||
|
||||
result = wp.shortcode.replace( 'foo', 'this [foo] has the [\n[foo param="bar"]] shortcode ', shortcodeReplaceCallback );
|
||||
equal( result, 'this bar has the [\nbar] shortcode ', 'escaping with newlines should not actually escape the content' );
|
||||
});
|
||||
|
||||
test( 'replace() should not replace the shortcode when it is an incomplete match', function() {
|
||||
var result;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user