Skip to content

Commit

Permalink
Fix regular expression Automattic#68
Browse files Browse the repository at this point in the history
Shortcode names and attributes are separated by at least one space.
  • Loading branch information
mpgo13 committed Aug 5, 2017
1 parent d1f1679 commit 421a633
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion syntaxhighlighter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
( function($) {
var shortcodes = window.syntaxHLcodes || 'sourcecode',
regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );
regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );

window.syntaxHLescape = {};

Expand Down
2 changes: 1 addition & 1 deletion syntaxhighlighter_mce-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tinymce.PluginManager.add( 'syntaxhighlighter', function( editor ) {
editor.on( 'BeforeSetContent', function( event ) {
var shortcodes = window.syntaxHLcodes || 'sourcecode',
regex = new RegExp( '(?:<p>\\s*)?(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?(?:\\s*<\\/p>)?', 'gi' );
regex = new RegExp( '(?:<p>\\s*)?(?:<pre>\\s*)?(\\[(' + shortcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?(?:\\s*<\\/p>)?', 'gi' );

if ( event.content && event.content.indexOf( '[' ) !== -1 ) {
event.content = event.content.replace( regex, function( match, shortcode ) {
Expand Down
10 changes: 5 additions & 5 deletions syntaxhighlighter_mce.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if ( typeof syntaxHLcodes == 'undefined' ) {
_visualToHtml : function(content) {
content = tinymce.trim(content);
// 2 <br> get converted to \n\n and are needed to preserve the next <p>
content = content.replace(new RegExp('(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\3\\])(\\s*<\\/pre>)?', 'gi'),
content = content.replace(new RegExp('(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\3\\])(\\s*<\\/pre>)?', 'gi'),
function(a) {
a = a.replace( /<br \/>([\t ])/g, '<br \/><%%KEEPWHITESPACE%%>$1' );
return a + '<br /><br />';
Expand All @@ -51,14 +51,14 @@ if ( typeof syntaxHLcodes == 'undefined' ) {
_htmlToVisual : function(content) {
content = tinymce.trim(content);

content = content.replace(new RegExp('(<p>\\s*)?(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\4\\])(\\s*<\\/pre>)?(\\s*<\\/p>)?', 'gi'), '<pre>$3</pre>');
content = content.replace(new RegExp('(<p>\\s*)?(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\4\\])(\\s*<\\/pre>)?(\\s*<\\/p>)?', 'gi'), '<pre>$3</pre>');
content = content.replace(/<\/pre><pre>/gi, '\n');

// Remove anonymous, empty paragraphs.
content = content.replace(/<p>(\s|&nbsp;)*<\/p>/mg, '');

// Look for <p> <br> in the [tag]s, replace with <br />
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
function(a) {
return a.replace(/<br ?\/?>[\r\n]*/g, '<br />').replace(/<\/?p( [^>]*)?>[\r\n]*/g, '<br />');
});
Expand All @@ -85,7 +85,7 @@ function pre_wpautop2(content) {

content = this._pre_wpautop(content);

content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
function(a) {
return a.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').replace(/<%%KEEPWHITESPACE%%>/g, '');
});
Expand All @@ -95,7 +95,7 @@ function pre_wpautop2(content) {

function wpautop2(content) {
// js htmlspecialchars
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
function(a) {
return a.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
});
Expand Down

0 comments on commit 421a633

Please sign in to comment.