Browse Source

Fixes #13845: `mt_rand()` is not used instead of `rand()` in `yii\captcha\CaptchaAction` + minor code improvements

tags/2.0.12
Vladimir Reznichenko 8 years ago committed by Alexander Makarov
parent
commit
6da1ec6fb2
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A
  1. 1
      framework/CHANGELOG.md
  2. 8
      framework/captcha/CaptchaAction.php
  3. 4
      framework/console/controllers/MessageController.php
  4. 2
      framework/db/mssql/QueryBuilder.php
  5. 2
      framework/helpers/BaseHtml.php
  6. 6
      framework/helpers/BaseInflector.php
  7. 2
      framework/web/CookieCollection.php

1
framework/CHANGELOG.md

@ -55,6 +55,7 @@ Yii Framework 2 Change Log
- Bug #13704: Fixed `yii\validators\UniqueValidator` to prefix attribute name with model's database table name (vladis84)
- Enh #13823: Refactored migrations template (Kolyunya)
- Bug #13822: Fixed `yii\web\User::loginRequired()` to throw an `UnauthorizedHttpException` instead of a `ForbiddenHttpException` (Kolyunya)
- Enh #13845: `mt_rand()` is not used instead of `rand()` in `yii\captcha\CaptchaAction` (kalessil)
2.0.11.2 February 08, 2017
--------------------------

8
framework/captcha/CaptchaAction.php

@ -297,8 +297,8 @@ class CaptchaAction extends Action
$x = 10;
$y = round($this->height * 27 / 40);
for ($i = 0; $i < $length; ++$i) {
$fontSize = (int) (rand(26, 32) * $scale * 0.8);
$angle = rand(-10, 10);
$fontSize = (int) (mt_rand(26, 32) * $scale * 0.8);
$angle = mt_rand(-10, 10);
$letter = $code[$i];
$box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter);
$x = $box[2] + $this->offset;
@ -340,9 +340,9 @@ class CaptchaAction extends Action
for ($i = 0; $i < $length; ++$i) {
$draw = new \ImagickDraw();
$draw->setFont($this->fontFile);
$draw->setFontSize((int) (rand(26, 32) * $scale * 0.8));
$draw->setFontSize((int) (mt_rand(26, 32) * $scale * 0.8));
$draw->setFillColor($foreColor);
$image->annotateImage($draw, $x, $y, rand(-10, 10), $code[$i]);
$image->annotateImage($draw, $x, $y, mt_rand(-10, 10), $code[$i]);
$fontMetrics = $image->queryFontMetrics($draw, $code[$i]);
$x += (int) $fontMetrics['textWidth'] + $this->offset;
}

4
framework/console/controllers/MessageController.php

@ -534,11 +534,11 @@ EOD;
if (isset($buffer[0][0], $buffer[1], $buffer[2][0]) && $buffer[0][0] === T_CONSTANT_ENCAPSED_STRING && $buffer[1] === ',' && $buffer[2][0] === T_CONSTANT_ENCAPSED_STRING) {
// is valid call we can extract
$category = stripcslashes($buffer[0][1]);
$category = mb_substr($category, 1, mb_strlen($category) - 2);
$category = mb_substr($category, 1, -1);
if (!$this->isCategoryIgnored($category, $ignoreCategories)) {
$message = stripcslashes($buffer[2][1]);
$message = mb_substr($message, 1, mb_strlen($message) - 2);
$message = mb_substr($message, 1, -1);
$messages[$category][] = $message;
}

2
framework/db/mssql/QueryBuilder.php

@ -215,7 +215,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
public function checkIntegrity($check = true, $schema = '', $table = '')
{
$enable = $check ? 'CHECK' : 'NOCHECK';
$schema = $schema ? $schema : $this->db->getSchema()->defaultSchema;
$schema = $schema ?: $this->db->getSchema()->defaultSchema;
$tableNames = $this->db->getTableSchema($table) ? [$table] : $this->db->getSchema()->getTableNames($schema);
$viewNames = $this->db->getSchema()->getViewNames($schema);
$tableNames = array_diff($tableNames, $viewNames);

2
framework/helpers/BaseHtml.php

@ -1221,7 +1221,7 @@ class BaseHtml
foreach ($model->getErrors() as $errors) {
foreach ($errors as $error) {
$line = $encode ? Html::encode($error) : $error;
if (array_search($line, $lines) === false) {
if (!in_array($line, $lines, true)) {
$lines[] = $line;
}
if (!$showAllErrors) {

6
framework/helpers/BaseInflector.php

@ -362,7 +362,7 @@ class BaseInflector
*/
public static function camel2words($name, $ucwords = true)
{
$label = trim(strtolower(str_replace([
$label = strtolower(trim(str_replace([
'-',
'_',
'.',
@ -384,9 +384,9 @@ class BaseInflector
{
$regex = $strict ? '/[A-Z]/' : '/(?<![A-Z])[A-Z]/';
if ($separator === '_') {
return trim(strtolower(preg_replace($regex, '_\0', $name)), '_');
return strtolower(trim(preg_replace($regex, '_\0', $name), '_'));
} else {
return trim(strtolower(str_replace('_', $separator, preg_replace($regex, $separator . '\0', $name))), $separator);
return strtolower(trim(str_replace('_', $separator, preg_replace($regex, $separator . '\0', $name)), $separator));
}
}

2
framework/web/CookieCollection.php

@ -34,7 +34,7 @@ class CookieCollection extends Object implements \IteratorAggregate, \ArrayAcces
/**
* @var Cookie[] the cookies in this collection (indexed by the cookie names)
*/
private $_cookies = [];
private $_cookies;
/**

Loading…
Cancel
Save