[wp-trac] [WordPress Trac] #43686: Shortcodes containing asterisks may create invalid regex breaking the editor
WordPress Trac
noreply at wordpress.org
Sun Apr 8 18:32:35 UTC 2018
#43686: Shortcodes containing asterisks may create invalid regex breaking the
editor
------------------------------------------------+--------------------------
Reporter: Vusys | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting
Component: Shortcodes | Review
Severity: normal | Version: 4.9.4
Keywords: has-patch dev-feedback 2nd-opinion | Resolution:
| Focuses:
| administration
------------------------------------------------+--------------------------
Changes (by soulseekah):
* keywords: => has-patch dev-feedback 2nd-opinion
Comment:
The Word count functionality breaks if there's a registered shortcode with
asterisk character in it.
Shortcode:
{{{
add_shortcode( '*stars*', function() {
return '★★★';
} );
}}}
Note, that the * symbol is specifically allowed in shortcode names as per
the tests:
`Tests_Shortcode::test_registration_good with data set #2
('unreserved!#$%()*+,-.;?@^_{|}~chars', true)`
The error?
{{{
word-count.js?ver=5.0-alpha-42125-src:64 Uncaught SyntaxError: Invalid
regular expression:
/\[\/?(?:wp_caption|caption|gallery|playlist|audio|video|embed|*stars*)[^\]]*?\]/:
Nothing to repeat
at new RegExp (<anonymous>)
at new WordCounter (word-count.js?ver=5.0-alpha-42125-src:64)
at post.js?ver=5.0-alpha-42125-src:1270
}}}
`this.settings.shortcodesRegExp·=·new·RegExp(·'\\[\\/?(?:'·+·shortcodes.join(·'|'·)·+·')[^\\]]*?\\]',·'g'·);`,
where shortcodes is a JSON object:
{{{
/* <![CDATA[ */
var wordCountL10n =
{"type":"words","shortcodes":["wp_caption","caption","gallery","playlist","audio","video","embed","*stars*"]};
/* ]]> */
}}}
43686.diff patches the regular expression escaping all special characters
as needed.
I suspect that other issues may arise, since there may be other regular
expressions in there. Your QTags error is probably related, but it would
be crucial to see your QTags addition code to see what you're doing,
otherwise no other errors are occurring on a clean WordPress install.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43686#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list