Skip to content

Commit b8f2ee6

Browse files
AC-3170: Incorrect processing order of Email template directives
1 parent c2d5a96 commit b8f2ee6

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

lib/internal/Magento/Framework/Filter/Template.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,7 @@ private function processDirectives($value, $isSigned = false): array
266266
$pattern = $directiveProcessor->getRegularExpression();
267267

268268
if ($isSigned) {
269-
$signature = $this->signatureProvider->get();
270-
271-
$pattern = substr_replace($pattern, $signature, strpos($pattern, '/') + 1, 0);
272-
$pattern = substr_replace($pattern, $signature, strrpos($pattern, '/'), 0);
269+
$pattern = $this->embedSignatureIntoPattern($pattern);
273270
}
274271

275272
if (preg_match_all($pattern, $value, $constructions, PREG_SET_ORDER)) {
@@ -287,6 +284,38 @@ private function processDirectives($value, $isSigned = false): array
287284
return $results;
288285
}
289286

287+
/**
288+
* Modifies given regular expression pattern to be able to recognize signed directives.
289+
*
290+
* @param string $pattern
291+
*
292+
* @return string
293+
*
294+
* @throws \Magento\Framework\Exception\LocalizedException
295+
*/
296+
private function embedSignatureIntoPattern(string $pattern): string
297+
{
298+
$signature = $this->signatureProvider->get();
299+
300+
$closingDelimiters = [
301+
'(' => ')',
302+
'{' => '}',
303+
'[' => ']',
304+
'<' => '>'
305+
];
306+
307+
$closingDelimiter = $openingDelimiter = substr(trim($pattern), 0, 1);
308+
309+
if (array_key_exists($openingDelimiter, $closingDelimiters)) {
310+
$closingDelimiter = $closingDelimiters[$openingDelimiter];
311+
}
312+
313+
$pattern = substr_replace($pattern, $signature, strpos($pattern, $openingDelimiter) + 1, 0);
314+
$pattern = substr_replace($pattern, $signature, strrpos($pattern, $closingDelimiter), 0);
315+
316+
return $pattern;
317+
}
318+
290319
/**
291320
* Runs callbacks that have been added to filter content after directive processing is finished.
292321
*

0 commit comments

Comments
 (0)