BUG: Matching fails with more than one shortcode on each line
-
I have a shortcode like this:
`
<div class=”container-fluid text-center text-{{color:black}} bg-{{bgcolor:light}}”>
<p>here is text</p>
</div>
`
If I do this, and call [myshortcode], I get
`
<div class=”container-fluid text-center text-black”>
<p>here is text</p>
</div>
`
which isn’t right, as it completely eliminated the second shortcode by greedy matching. It’s clear the current code is a bug.
The fix is in util.php in this regex. I’ve done a regex that will match anything but a } character instead of any character. Technically you’d probably want it to match two braces, but I think it’s clear a brace is an invalid character when using your plugin. You can of course make it work with the pair of braces if you wish.
`
— utils.bak 2018-03-21 23:01:15.669372954 -0400
+++ utils.php 2018-03-21 23:09:15.133401455 -0400
@@ -33,7 +33,7 @@
static public function replace_placeholders($placeholders, $html) {
foreach ($placeholders as $placeholder) {
$replacement = !empty($placeholder[‘value’]) ? $placeholder[‘value’] : Placeholders::get_placeholder_value($placeholder[‘name’]);
– $html = preg_replace(‘/{{‘. $placeholder[‘name’] .'(?::.+){0,1}}}/i’, $replacement, $html);
+ $html = preg_replace(‘/{{‘. $placeholder[‘name’] .'(?::([^}])+){0,1}}}/i’, $replacement, $html);
}
return $html;
}
`
- The topic ‘BUG: Matching fails with more than one shortcode on each line’ is closed to new replies.