[Plugin: Content Molecules] Minor bug in using $ inside value strings
-
Great little plugin Marcus, but I’ve encountered a small bug.
Consider using [m id=”test” price=”$10.00″] when the test template is “Price: {price}”
You get in your output
Price: .00
Since this example is effectively processed using
preg_replace('/{price}/i', '$10.00', 'Price: {price}');
the $10 is interpreted by preg_replace as the 10th parenthesized match in the pattern – this means the $10 is stripped from the replacement string resulting in the price of .00.
If you try [m id=”test” price=”$100.00″], the output will be Price: 0.00 because the $n feature only allows n from 0 to 99, so $10 is stripped.
Not sure why you’re using preg_replace here since it is a simple string replacement, so I think you could use str_ireplace for this part of your code and avoid this problem.
Alternatively, you could replace $ in the replacement string with \$ before using preg_replace.
Tony
https://www.ads-software.com/extend/plugins/content-molecules/
- The topic ‘[Plugin: Content Molecules] Minor bug in using $ inside value strings’ is closed to new replies.