Skip to content
Permalink
Browse files

regexp: \z replaced with D modifier

  • Loading branch information...
dg committed Jul 11, 2019
1 parent d811678 commit 08250b28cecf7224490022368c3fd017656736f5
@@ -45,7 +45,7 @@ public function __construct(Router $router, Nette\Http\UrlScript $refUrl, IPrese
*/
public function link(string $dest, array $params = []): string
{
if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $dest, $m)) {
if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()$~D', $dest, $m)) {
throw new UI\InvalidLinkException("Invalid link destination '$dest'.");
}
[, $presenter, $action, $frag] = $m;
@@ -60,7 +60,7 @@ public function getPresenterClass(string &$name): string
return $this->cache[$name];
}
if (!Nette\Utils\Strings::match($name, '#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*\z#')) {
if (!Nette\Utils\Strings::match($name, '#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*$#D')) {
throw new InvalidPresenterException("Presenter name must be alphanumeric string, '$name' is invalid.");
}
@@ -97,7 +97,7 @@ public function setMapping(array $mapping)
{
foreach ($mapping as $module => $mask) {
if (is_string($mask)) {
if (!preg_match('#^\\\\?([\w\\\\]*\\\\)?(\w*\*\w*?\\\\)?([\w\\\\]*\*\w*)\z#', $mask, $m)) {
if (!preg_match('#^\\\\?([\w\\\\]*\\\\)?(\w*\*\w*?\\\\)?([\w\\\\]*\*\w*)$#D', $mask, $m)) {
throw new Nette\InvalidStateException("Invalid mapping mask '$mask'.");
}
$this->mapping[$module] = [$m[1], $m[2] ?: '*Module\\', $m[3]];
@@ -137,7 +137,7 @@ public function unformatPresenterClass(string $class): ?string
{
foreach ($this->mapping as $module => $mapping) {
$mapping = str_replace(['\\', '*'], ['\\\\', '(\w+)'], $mapping);
if (preg_match("#^\\\\?$mapping[0]((?:$mapping[1])*)$mapping[2]\\z#i", $class, $matches)) {
if (preg_match("#^\\\\?$mapping[0]((?:$mapping[1])*)$mapping[2]$#Di", $class, $matches)) {
return ($module === '*' ? '' : $module . ':')
. preg_replace("#$mapping[1]#iA", '$1:', $matches[1]) . $matches[3];
}
@@ -91,7 +91,7 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt
if ($this->resuming) {
$httpResponse->setHeader('Accept-Ranges', 'bytes');
if (preg_match('#^bytes=(\d*)-(\d*)\z#', (string) $httpRequest->getHeader('Range'), $matches)) {
if (preg_match('#^bytes=(\d*)-(\d*)$#D', (string) $httpRequest->getHeader('Range'), $matches)) {
[, $start, $end] = $matches;
if ($start === '') {
$start = max(0, $filesize - $end);
@@ -207,7 +207,7 @@ public static function convertType(&$val, string $type, bool $isClass = false):
} else {
$tmp = ($val === false ? '0' : (string) $val);
if ($type === 'double' || $type === 'float') {
$tmp = preg_replace('#\.0*\z#', '', $tmp);
$tmp = preg_replace('#\.0*$#D', '', $tmp);
}
$orig = $tmp;
settype($tmp, $type);
@@ -226,7 +226,7 @@ public static function convertType(&$val, string $type, bool $isClass = false):
*/
public static function parseAnnotation(\Reflector $ref, string $name): ?array
{
if (!preg_match_all('#[\\s*]@' . preg_quote($name, '#') . '(?:\(\\s*([^)]*)\\s*\)|\\s|$)#', (string) $ref->getDocComment(), $m)) {
if (!preg_match_all('#[\s*]@' . preg_quote($name, '#') . '(?:\(\s*([^)]*)\s*\)|\s|$)#', (string) $ref->getDocComment(), $m)) {
return null;
}
static $tokens = ['true' => true, 'false' => false, 'null' => null];
@@ -1186,7 +1186,7 @@ private function initGlobalParameters(): void
}
foreach ($params as $key => $value) {
if (!preg_match('#^((?:[a-z0-9_]+-)*)((?!\d+\z)[a-z0-9_]+)\z#i', (string) $key, $matches)) {
if (!preg_match('#^((?:[a-z0-9_]+-)*)((?!\d+$)[a-z0-9_]+)$#Di', (string) $key, $matches)) {
continue;
} elseif (!$matches[1]) {
$selfParams[$key] = $value;
@@ -1197,7 +1197,7 @@ private function initGlobalParameters(): void
// init & validate $this->action & $this->view
$action = $selfParams[self::ACTION_KEY] ?? self::DEFAULT_ACTION;
if (!is_string($action) || !Nette\Utils\Strings::match($action, '#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*\z#')) {
if (!is_string($action) || !Nette\Utils\Strings::match($action, '#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*$#D')) {
$this->error('Action name is not valid.');
}
$this->changeAction($action);
@@ -80,7 +80,7 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
}
$name = $writer->formatWord($words[0]);
$method = ucfirst($words[1] ?? '');
$method = Strings::match($method, '#^\w*\z#') ? "render$method" : "{\"render$method\"}";
$method = Strings::match($method, '#^\w*$#D') ? "render$method" : "{\"render$method\"}";
$tokens = $node->tokenizer;
$pos = $tokens->position;
@@ -113,7 +113,7 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
*/
public function macroLink(MacroNode $node, PhpWriter $writer)
{
$node->modifiers = preg_replace('#\|safeurl\s*(?=\||\z)#i', '', $node->modifiers);
$node->modifiers = preg_replace('#\|safeurl\s*(?=\||$)#Di', '', $node->modifiers);
return $writer->using($node)
->write('echo %escape(%modify('
. ($node->name === 'plink' ? '$this->global->uiPresenter' : '$this->global->uiControl')

0 comments on commit 08250b2

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