Skip to content
Permalink
Browse files

regexp: \z replaced with D modifier

  • Loading branch information...
dg committed Jul 11, 2019
1 parent 9b045ee commit 9dd5992f9ae7c385fd7461caadbe5a9af9e9a8fa
@@ -687,14 +687,14 @@ public function expandMacro(string $name, string $args, string $modifiers = null
if (strpbrk($name, '=~%^&_')) {
if (in_array($this->context, [self::CONTEXT_HTML_ATTRIBUTE_URL, self::CONTEXT_HTML_ATTRIBUTE_UNQUOTED_URL], true)) {
if (!Helpers::removeFilter($modifiers, 'nocheck') && !preg_match('#\|datastream(?=\s|\||\z)#i', $modifiers)) {
if (!Helpers::removeFilter($modifiers, 'nocheck') && !preg_match('#\|datastream(?=\s|\||$)#Di', $modifiers)) {
$modifiers .= '|checkurl';
}
}
if (!Helpers::removeFilter($modifiers, 'noescape')) {
$modifiers .= '|escape';
if ($this->context === self::CONTEXT_HTML_JS && $name === '=' && preg_match('#["\'] *\z#', $this->tokens[$this->position - 1]->text)) {
if ($this->context === self::CONTEXT_HTML_JS && $name === '=' && preg_match('#["\'] *$#D', $this->tokens[$this->position - 1]->text)) {
throw new CompileException("Do not place {$this->tokens[$this->position]->text} inside quotes.");
}
}
@@ -266,7 +266,7 @@ private function contextNone()
private function contextMacro(): void
{
$matches = $this->match('~
(?P<comment>\\*.*?\\*' . $this->delimiters[1] . '\n{0,2})|
(?P<comment>\*.*?\*' . $this->delimiters[1] . '\n{0,2})|
(?P<macro>(?>
' . self::RE_STRING . '|
\{(?>' . self::RE_STRING . '|[^\'"{}])*+\}|
@@ -392,8 +392,8 @@ public function parseMacroTag(string $tag): ?array
(?P<shortname>[=\~#%^&_]?) ## expression, =expression, ...
)(?P<args>(?:' . self::RE_STRING . '|[^\'"])*?)
(?P<modifiers>(?<!\|)\|[a-z](?P<modArgs>(?:' . self::RE_STRING . '|(?:\((?P>modArgs)\))|[^\'"/()]|/(?=.))*+))?
(?P<empty>/?\z)
()\z~isx', $tag, $match)) {
(?P<empty>/?$)
()$~Disx', $tag, $match)) {
if (preg_last_error()) {
throw new RegexpException(null, preg_last_error());
}
@@ -145,7 +145,7 @@ public function formatArray(MacroTokens $tokens = null): string
*/
public function formatWord(string $s): string
{
return (is_numeric($s) || preg_match('#^\$|[\'"]|^(true|TRUE)\z|^(false|FALSE)\z|^(null|NULL)\z|^[\w\\\\]{3,}::[A-Z0-9_]{2,}\z#', $s))
return (is_numeric($s) || preg_match('#^\$|[\'"]|^(true|TRUE)$|^(false|FALSE)$|^(null|NULL)$|^[\w\\\\]{3,}::[A-Z0-9_]{2,}$#D', $s))
? $this->formatArgs(new MacroTokens($s))
: '"' . $s . '"';
}
@@ -211,7 +211,7 @@ private function isExpired(string $file, string $name): bool
public function getCacheFile(string $name): string
{
$hash = substr($this->getTemplateClass($name), 8);
$base = preg_match('#([/\\\\][\w@.-]{3,35}){1,3}\z#', $name, $m)
$base = preg_match('#([/\\\\][\w@.-]{3,35}){1,3}$#D', $name, $m)
? preg_replace('#[^\w@.-]+#', '-', substr($m[0], 1)) . '--'
: '';
return "$this->tempDirectory/$base$hash.php";
@@ -55,7 +55,7 @@ public static function getSuggestion(array $items, $value): ?string
public static function removeFilter(string &$modifier, string $filter): bool
{
$modifier = preg_replace('#\|(' . $filter . ')\s?(?=\||\z)#i', '', $modifier, -1, $found);
$modifier = preg_replace('#\|(' . $filter . ')\s?(?=\||$)#Di', '', $modifier, -1, $found);
return (bool) $found;
}
@@ -101,7 +101,7 @@ public function macroInclude(MacroNode $node, PhpWriter $writer)
{
$node->replaced = false;
$destination = $node->tokenizer->fetchWord(); // destination [,] [params]
if (!preg_match('~#|[\w-]+\z~A', $destination)) {
if (!preg_match('~#|[\w-]+$~DA', $destination)) {
return false;
}
@@ -350,14 +350,14 @@ public function macroBlockEnd(MacroNode $node, PhpWriter $writer)
$node->content = '<?php $this->global->snippetDriver->enter('
. $writer->formatWord(substr($node->data->name, 1))
. ', "' . $type . '"); ?>'
. preg_replace('#(?<=\n)[ \t]+\z#', '', $node->content) . '<?php $this->global->snippetDriver->leave(); ?>';
. preg_replace('#(?<=\n)[ \t]+$#D', '', $node->content) . '<?php $this->global->snippetDriver->leave(); ?>';
}
if (empty($node->data->leave)) {
if (preg_match('#\$|n:#', $node->content)) {
$node->content = '<?php ' . (isset($node->data->args) ? 'extract($this->params); ' . $node->data->args : 'extract($_args);') . ' ?>'
. $node->content;
}
$this->namedBlocks[$node->data->name] = $tmp = preg_replace('#^\n+|(?<=\n)[ \t]+\z#', '', $node->content);
$this->namedBlocks[$node->data->name] = $tmp = preg_replace('#^\n+|(?<=\n)[ \t]+$#D', '', $node->content);
$node->content = substr_replace($node->content, $node->openingCode . "\n", strspn($node->content, "\n"), strlen($tmp));
$node->openingCode = '<?php ?>';
@@ -393,12 +393,12 @@ public function macroIfset(MacroNode $node, PhpWriter $writer)
if ($node->modifiers) {
throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
}
if (!preg_match('~#|[\w-]+\z~A', $node->args)) {
if (!preg_match('~#|[\w-]+$~DA', $node->args)) {
return false;
}
$list = [];
while (($name = $node->tokenizer->fetchWord()) !== null) {
$list[] = preg_match('~#|[\w-]+\z~A', $name)
$list[] = preg_match('~#|[\w-]+$~DA', $name)
? '$this->blockQueue["' . ltrim($name, '#') . '"]'
: $writer->formatArgs(new Latte\MacroTokens($name));
}
@@ -188,7 +188,7 @@ public static function escapeICal($s): string
*/
public static function escapeHtmlRawText($s): string
{
return preg_replace('#</(script|style)#i', '<\\/$1', (string) $s);
return preg_replace('#</(script|style)#i', '<\/$1', (string) $s);
}
@@ -292,7 +292,7 @@ public static function getConvertor(string $source, string $dest): ?callable
public static function safeUrl($s): string
{
$s = (string) $s;
return preg_match('~^(?:(?:https?|ftp)://[^@]+(?:/.*)?|mailto:.+|[/?#].*|[^:]+)\z~i', $s) ? $s : '';
return preg_match('~^(?:(?:https?|ftp)://[^@]+(?:/.*)?|mailto:.+|[/?#].*|[^:]+)$~Di', $s) ? $s : '';
}
@@ -357,7 +357,7 @@ public static function indent(FilterInfo $info, string $s, int $level = 1, strin
if ($level < 1) {
// do nothing
} elseif (in_array($info->contentType, [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], true)) {
$s = preg_replace_callback('#<(textarea|pre).*?</\\1#si', function ($m) {
$s = preg_replace_callback('#<(textarea|pre).*?</\1#si', function ($m) {
return strtr($m[0], " \t\r\n", "\x1F\x1E\x1D\x1A");
}, $s);
if (preg_last_error()) {
@@ -589,7 +589,7 @@ private static function strLength(string $s): int
public static function trim(FilterInfo $info, $s, string $charlist = " \t\n\r\0\x0B\u{A0}"): string
{
$charlist = preg_quote($charlist, '#');
$s = preg_replace('#^[' . $charlist . ']+|[' . $charlist . ']+\z#u', '', (string) $s);
$s = preg_replace('#^[' . $charlist . ']+|[' . $charlist . ']+$#Du', '', (string) $s);
if (preg_last_error()) {
throw new Latte\RegexpException(null, preg_last_error());
}

0 comments on commit 9dd5992

Please sign in to comment.
You can’t perform that action at this time.