paragraphs inserted round shortcodes by wpautop not working properly for tag-end-tag paits
|Reported by:||alanjohndix||Owned by:|
The regex returned by get_shortcode_regex() had a back-reference '\[\/\2\]' to match balanced tag-end-tag pairs such as "[x]textx". The regex assumes it will be used 'bare' as a regular expression. However, wpautop adds extra enclosing brackets to be able to refer to the entire matched tags and content. This means that the back-reference instead matches the (optional) preceding letter which is usually blank and thus the closing tag does not match properly.
In the case of single tag-end-tag pair, this means that
ends up as
This gets more complicated when there are internal tags such as:
[mytag] some [specialsymbol] text mytag
As in some cases the existing .*? for attribute matching chomps everything while it tries to find a '/'.
A simple fix would be to add an optional parameter to get_shortcode_regex($nested=0) and use this to modify the regular expression. This would give the intended match for the shortcode regex, but in fact makes things worse. Looking at the same source:
it would generate (assuming [divtag] generates a div):
The attached patch addresses this by adding two new functions to shortcodes.php returning regular expressions for matching begin and end tags separately. wpautop then has two separate preg_replace lines doing the <p> fixes.
At the same time I swopped the .*? for attribute matching to [\]]*?
I guess slightly slower, but doesn't risk chomping the entire post as an attribute.
Note: Sorry, the end tags above all come out odd, but don't know the TRAC editor so don't know how to tell it to treat them as literals. I've done a nicely formatted version of the report at: