diff --git a/build/controllers/ReleaseController.php b/build/controllers/ReleaseController.php index 2b372cd842..d839885270 100644 --- a/build/controllers/ReleaseController.php +++ b/build/controllers/ReleaseController.php @@ -990,7 +990,7 @@ class ReleaseController extends Controller protected function updateYiiVersion($frameworkPath, $version) { $this->sed( - '/function getVersion\(\)\R \{\R return \'(.+?)\';/', + '/function getVersion\(\)\R {4}\{\R {8}return \'(.+?)\';/', "function getVersion()\n {\n return '$version';", $frameworkPath . '/BaseYii.php'); } diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 8964d6675a..614241d0f3 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -701,7 +701,7 @@ class Controller extends \yii\base\Controller protected function parseDocCommentTags($reflection) { $comment = $reflection->getDocComment(); - $comment = "@description \n" . strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($comment, '/'))), "\r", ''); + $comment = "@description \n" . strtr(trim(preg_replace('/^\s*\**([ \t])?/m', '', trim($comment, '/'))), "\r", ''); $parts = preg_split('/^\s*@/m', $comment, -1, PREG_SPLIT_NO_EMPTY); $tags = []; foreach ($parts as $part) { @@ -744,7 +744,7 @@ class Controller extends \yii\base\Controller */ protected function parseDocCommentDetail($reflection) { - $comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($reflection->getDocComment(), '/'))), "\r", ''); + $comment = strtr(trim(preg_replace('/^\s*\**([ \t])?/m', '', trim($reflection->getDocComment(), '/'))), "\r", ''); if (preg_match('/^\s*@\w+/m', $comment, $matches, PREG_OFFSET_CAPTURE)) { $comment = trim(substr($comment, 0, $matches[0][1])); } diff --git a/framework/console/controllers/AssetController.php b/framework/console/controllers/AssetController.php index cd9c3aeaff..5215066df4 100644 --- a/framework/console/controllers/AssetController.php +++ b/framework/console/controllers/AssetController.php @@ -677,7 +677,7 @@ EOD; return str_replace($inputUrl, $outputUrl, $fullMatch); }; - $cssContent = preg_replace_callback('/url\(["\']?([^)^"^\']*)["\']?\)/i', $callback, $cssContent); + $cssContent = preg_replace_callback('/url\(["\']?([^)^"\']*)["\']?\)/i', $callback, $cssContent); return $cssContent; } diff --git a/framework/db/ActiveRecord.php b/framework/db/ActiveRecord.php index 0b95da9e62..130285617e 100644 --- a/framework/db/ActiveRecord.php +++ b/framework/db/ActiveRecord.php @@ -214,7 +214,7 @@ class ActiveRecord extends BaseActiveRecord $aliases = array_diff(array_keys($tables), $tables); return array_map(function ($alias) { - return preg_replace('/{{([\w]+)}}/', '$1', $alias); + return preg_replace('/{{(\w+)}}/', '$1', $alias); }, array_values($aliases)); } diff --git a/framework/db/sqlite/Command.php b/framework/db/sqlite/Command.php index 36b2b73124..8bf4c16ec0 100644 --- a/framework/db/sqlite/Command.php +++ b/framework/db/sqlite/Command.php @@ -101,7 +101,7 @@ class Command extends \yii\db\Command */ private function extractUsedParams(SqlToken $statement, $params) { - preg_match_all('/(?P[:][a-zA-Z0-9_]+)/', $statement->getSql(), $matches, PREG_SET_ORDER); + preg_match_all('/(?P:\w+)/', $statement->getSql(), $matches, PREG_SET_ORDER); $result = []; foreach ($matches as $match) { $phName = ltrim($match['placeholder'], ':'); diff --git a/framework/helpers/BaseStringHelper.php b/framework/helpers/BaseStringHelper.php index ba0975fa7e..da13416310 100644 --- a/framework/helpers/BaseStringHelper.php +++ b/framework/helpers/BaseStringHelper.php @@ -476,7 +476,7 @@ class BaseStringHelper return $string; } - $parts = preg_split('/(\s+[^\w]+\s+|^[^\w]+\s+|\s+)/u', $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\s+\W+\s+|^\W+\s+|\s+)/u', $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $ucfirstEven = trim(mb_substr($parts[0], -1, 1, $encoding)) === ''; foreach ($parts as $key => $value) { $isEven = (bool)($key % 2); diff --git a/framework/validators/IpValidator.php b/framework/validators/IpValidator.php index 3bab5f5c3d..c4a9555bf8 100644 --- a/framework/validators/IpValidator.php +++ b/framework/validators/IpValidator.php @@ -115,11 +115,11 @@ class IpValidator extends Validator /** * @var string Regexp-pattern to validate IPv4 address */ - public $ipv4Pattern = '/^(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))$/'; + public $ipv4Pattern = '/^(?:(?:2(?:[0-4]\d|5[0-5])|[0-1]?\d?\d)\.){3}(?:(?:2([0-4]\d|5[0-5])|[0-1]?\d?\d))$/'; /** * @var string Regexp-pattern to validate IPv6 address */ - public $ipv6Pattern = '/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/'; + public $ipv6Pattern = '/^(([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}|([\da-fA-F]{1,4}:){1,7}:|([\da-fA-F]{1,4}:){1,6}:[\da-fA-F]{1,4}|([\da-fA-F]{1,4}:){1,5}(:[\da-fA-F]{1,4}){1,2}|([\da-fA-F]{1,4}:){1,4}(:[\da-fA-F]{1,4}){1,3}|([\da-fA-F]{1,4}:){1,3}(:[\da-fA-F]{1,4}){1,4}|([\da-fA-F]{1,4}:){1,2}(:[\da-fA-F]{1,4}){1,5}|[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,6})|:((:[\da-fA-F]{1,4}){1,7}|:)|fe80:(:[\da-fA-F]{0,4}){0,4}%[\da-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d)|([\da-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[\d])?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d))$/'; /** * @var string user-defined error message is used when validation fails due to the wrong IP address format. * diff --git a/framework/web/Request.php b/framework/web/Request.php index 2c0d4eaccc..d3a716c97f 100644 --- a/framework/web/Request.php +++ b/framework/web/Request.php @@ -1198,7 +1198,7 @@ class Request extends \yii\base\Request { $ip = $this->getSecureForwardedHeaderTrustedPart('for'); if ($ip !== null && preg_match( - '/^\[?(?P(?:(?:(?:[0-9a-f]{1,4}:){1,6}(?:[0-9a-f]{1,4})?(?:(?::[0-9a-f]{1,4}){1,6}))|(?:[\d]{1,3}\.){3}[\d]{1,3}))\]?(?::(?P[\d]+))?$/', + '/^\[?(?P(?:(?:(?:[0-9a-f]{1,4}:){1,6}(?:[0-9a-f]{1,4})?(?:(?::[0-9a-f]{1,4}){1,6}))|(?:\d{1,3}\.){3}\d{1,3}))\]?(?::(?P\d+))?$/', $ip, $matches )) { diff --git a/framework/web/Response.php b/framework/web/Response.php index 8603b4ad90..bc06a4b04d 100644 --- a/framework/web/Response.php +++ b/framework/web/Response.php @@ -897,7 +897,7 @@ class Response extends \yii\base\Response if ($checkAjax && $request->getIsAjax()) { if ( in_array($statusCode, [301, 302]) - && preg_match('/Trident\/|MSIE[ ]/', (string)$request->userAgent) + && preg_match('/Trident\/|MSIE /', (string)$request->userAgent) ) { $statusCode = 200; }