Hello, all.
We cannot use special characters in snippet call, but i want to use them, too.
So, I tried to solve whole problem by parsing with Regex.
It seems to behave well, though some tests are not enough for relation to other functions.
Example of snippet call:[[Snippet? param1 = `?= ‵ [] &‵ &` ¶m2= ¶m3=[]?= ¶m4 ¶m?5=`[[Lea más...]]`]]
The result of parsing (var_dump $parameter):array
'param1' => string '?= ` [] &` &' (length=11)
'param2' => string '' (length=0)
'param3' => string '[]?=' (length=4)
'param5' => string '[[Lea más...]]' (length=15)
The behavior of this hacked code- First parameter's '&' is completed automatically (ex. param1)
- Parameters doesn't have value are ignored (ex. param4)
- Every '?' in parameter's name are cut (ex. param5)
- When a value is quoted with '`', we can use special characters excluding '`' (ex. param1, 6)
- When a value is not quoted with '`', we can use special characters excluding '`', '&', ']]' and space (ex. param2, 3)
- Only when a value is quoted with '`', '‵' or '‵' in the value is replaced with '`' (ex. param1)
- Multi-byte characters also are parsed well on my local server (XAMPP+PHP 4.4.7 & PHP 5.2.4), but my tests are not enough (ex. param5)
The difference between this code and original code- Space characters of left and right of parameters are trimmed. (ex. param1)
(In the case of original code, I guess first parameter of Example is parsed as 'param1 ' with space characters.) - '&' is parsed after parsing '‵' and '‵'.
The code in snippet call like '&paramx=`value`' is parsed as a parameter '&paramx' and a value. (ex. param1)
(In the case of original code, '&' are replaced with '&' at first. Then parameters are parsed.
Therefore, I guess the code is parsed as a parameter '¶mx' and a value.)
MODx 0.9.5-0.9.6.1
method 'evalSnippets' in /manager/includes/document.parser.class.inc.php
(Line numbers are the one of version 0.9.6.1)
line 784 (before): function evalSnippets($documentSource) {
preg_match_all('~\[\[(.*?)\]\]~', $documentSource, $matches);
line 784 (after): function evalSnippets($documentSource) {
preg_match_all('~\[\[((?:.*?(?:`(?:[^`]|[^]]\])*?`)?)*?)\]\]~', $documentSource, $matches);
line 836 (before): // current params
$currentSnippetParams= $snippetParams[$i];
if (!empty ($currentSnippetParams)) {
$tempSnippetParams= str_replace("?", "", $currentSnippetParams);
$splitter= "&";
if (strpos($tempSnippetParams, "&") > 0)
$tempSnippetParams= str_replace("&", "&", $tempSnippetParams);
//$tempSnippetParams = html_entity_decode($tempSnippetParams, ENT_NOQUOTES, $this->config['etomite_charset']); //FS#334 and FS#456
$tempSnippetParams= split($splitter, $tempSnippetParams);
$snippetParamCount= count($tempSnippetParams);
for ($x= 0; $x < $snippetParamCount; $x++) {
if (strpos($tempSnippetParams[$x], '=', 0)) {
if ($parameterTemp= explode("=", $tempSnippetParams[$x])) {
$fp= strpos($parameterTemp[1], '`');
$lp= strrpos($parameterTemp[1], '`');
if (!($fp === false && $lp === false))
$parameterTemp[1]= substr($parameterTemp[1], $fp +1, $lp -1);
$parameter[$parameterTemp[0]]= $parameterTemp[1];
}
}
}
}
line 836 (after): // current params
$currentSnippetParams= $snippetParams[$i];
if (!empty ($currentSnippetParams)) {
$tempSnippetParams= preg_replace("~^\s*\?\s*~", "", $currentSnippetParams);
$splitter= "&";
if (strpos($tempSnippetParams, $splitter) != 0)
$tempSnippetParams= $splitter . $tempSnippetParams;
//$tempSnippetParams = html_entity_decode($tempSnippetParams, ENT_NOQUOTES, $this->config['etomite_charset']); //FS#334 and FS#456
$snippetParamCount= preg_match_all("~" . $splitter
. "([^" . $splitter . "=]*(?:=\s*`[^`]*`"
. "|=[^" . $splitter . "\s]*"
. "|[^" . $splitter . "]*))~", $tempSnippetParams, $matches);
$tempSnippetParams= @ $matches[1];
for ($x= 0; $x < $snippetParamCount; $x++) {
if (preg_match('~([^=\s]*)\s*=\s*`?([^`]*)`?~', $tempSnippetParams[$x], $parameterTemp)) {
$parameterTemp[2]= preg_replace("~�*8245;|�*2035;~", "`", $parameterTemp[2]);
if (strpos($parameterTemp[2], "&") > 0)
$parameterTemp[2]= str_replace("&", "&", $parameterTemp[2]);
$parameterTemp[1]= str_replace("?", "", $parameterTemp[1]);
$parameter[$parameterTemp[1]]= $parameterTemp[2];
}
}
}