Closed TheMaaarc closed 5 years ago
https://github.com/luyadev/luya/blob/707c6f7e8a725ae779abb7853009382185ddc90b/core/TagParser.php#L42
Mit dem negativen Lookbehind (?<!\) sollte sich das Escapen von Klammern mittels Backslash ermöglichen lassen:
REGEX = '/(?<function>[a-z]+)\[(?<value>.*?)\]((?<!\\)\((?<sub>.*?)(?<!\\)\))?/mi';
Hier getestet: https://regex101.com/r/aNMm3o/1
Natürlich müssten die Escape-Character vor der Ausgabe entfernt werden.
Perfect! Thanks @rolandschaub i will add this regex rule and make some unit tests.
Yes, please test it first.
@rolandschaub i have made a new branch with the regex and a unit test which should not fail if everything works as expected.
If you like to test:
issue-1907
branchcomposer install
./vendor/bin/phpunit tests/core/TagParserTest.php
/(?<function>[a-z]+)\[(?<value>.*?)\]((?<!\\\)\((?<sub>.*?)(?<!\\\)\))?/mi
is working!
/(?<function>[a-z]+)\[(?<value>.*?)\]((?<!\\\\)\((?<sub>.*?)(?<!\\\\)\))?/mi
Four backslashes is the correct way to do it, see here:
Step 1: PHP turns \\\\
into two literal \\
Step 2: Regex turns these \\
into one literal \
If I use parentheses in the title part of the tag, the inner parentheses will close the link even if escaped.
Example:
Both examples result in:
<a href="...">Example file (PDF</a>)