Feature request from TommyKolkman, posted on GitHub Aug 24, 2016
Magento widgets strip special characters like a "+".
If I add something like:
{{widget type="Elephant\CFTextAndImage\Block\Widget\CFTextAndImage" language="nl_nl" title_default="++Hallo++"}}
The plusses are stripped. Now, in this case that's not that much of a problem, but in some cases we use base64 values there. When the base64 value has a plus, the value is instantly corrupted.
I've tried to track it down and came to the conclusion that there is a problem with the following file:
https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Filter/Template.php
The problem is in the tokenizer.
/**
* Return associative array of parameters.
*
* @param string $value raw parameters
* @return array
*/
protected function getParameters($value)
{
$tokenizer = new Template\Tokenizer\Parameter();
$tokenizer->setString($value);
$params = $tokenizer->tokenize();
foreach ($params as $key => $value) {
if (substr($value, 0, 1) === '$') {
$params[$key] = $this->getVariable(substr($value, 1), null);
}
}
return $params;
}
The $value, before added to the tokenizer is still correct. Afterwards, however, it's missing the plusses.
Now, I've tried writing up my own replacement for the tokenizer as quick fix, but that won't do. Can you guys fix this?
Temp fix (via di.xml of course):
// $params = $tokenizer->tokenize();
$params = array();
$count = 0;
$widget_values = explode( '"', $value );
$param_key = '';
foreach( $widget_values as $widget_value ){
if( $count == 2 ){
$count = 0;
}
if( $count == 0 ){
// It's a key
$param_key = trim( rtrim( $widget_value, '=' ) );
} else {
// It's a value
$params[ $param_key ] = trim( $widget_value );
}
$count++;
}
... View more