@@ -266,10 +266,7 @@ private function processDirectives($value, $isSigned = false): array
266
266
$ pattern = $ directiveProcessor ->getRegularExpression ();
267
267
268
268
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 );
273
270
}
274
271
275
272
if (preg_match_all ($ pattern , $ value , $ constructions , PREG_SET_ORDER )) {
@@ -287,6 +284,38 @@ private function processDirectives($value, $isSigned = false): array
287
284
return $ results ;
288
285
}
289
286
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
+
290
319
/**
291
320
* Runs callbacks that have been added to filter content after directive processing is finished.
292
321
*
0 commit comments