Commit be2828d5 by Qiang Xue

Fixes #5484: Fixed potential string suffix detection failure on 5.5.11

parent 7ba770eb
......@@ -479,7 +479,7 @@ class Generator extends \yii\gii\Generator
if ($this->isReservedKeyword($this->modelClass)) {
$this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
}
if ((empty($this->tableName) || substr_compare($this->tableName, '*', -1)) && $this->modelClass == '') {
if ((empty($this->tableName) || substr_compare($this->tableName, '*', -1, 1)) && $this->modelClass == '') {
$this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
}
}
......@@ -489,7 +489,7 @@ class Generator extends \yii\gii\Generator
*/
public function validateTableName()
{
if (strpos($this->tableName, '*') !== false && substr_compare($this->tableName, '*', -1)) {
if (strpos($this->tableName, '*') !== false && substr_compare($this->tableName, '*', -1, 1)) {
$this->addError('tableName', 'Asterisk is only allowed as the last character.');
return;
......
......@@ -267,7 +267,7 @@ class Generator extends \yii\gii\Generator
if ($this->isReservedKeyword($this->modelClass)) {
$this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
}
if ((empty($this->indexName) || substr_compare($this->indexName, '*', -1)) && $this->modelClass == '') {
if ((empty($this->indexName) || substr_compare($this->indexName, '*', -1, 1)) && $this->modelClass == '') {
$this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
}
}
......@@ -277,7 +277,7 @@ class Generator extends \yii\gii\Generator
*/
public function validateIndexName()
{
if (strpos($this->indexName, '*') !== false && substr_compare($this->indexName, '*', -1)) {
if (strpos($this->indexName, '*') !== false && substr_compare($this->indexName, '*', -1, 1)) {
$this->addError('indexName', 'Asterisk is only allowed as the last character.');
return;
......
......@@ -17,6 +17,7 @@ Yii Framework 2 Change Log
- Bug #5423: `yii\behaviors\Cors` causes "undefined index" error when its `cors` is configured (qiangxue)
- Bug #5424: `Html::addCssStyle()` wasn't correctly setting style passed in array (kartik-v, samdark)
- Bug #5435: Added extra checks to `yii\rbac\DbManager` to prevent database exceptions when `$userId` is empty (samdark)
- Bug #5484: Fixed potential string suffix detection failure on 5.5.11 (qiangxue)
- Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe)
- Enh #4040: Added `$viewFile` and `$params` to the `EVENT_BEFORE_RENDER` and `EVENT_AFTER_RENDER` events for `View` (qiangxue)
- Enh #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations (samdark)
......
......@@ -149,7 +149,7 @@ class HelpController extends Controller
if (is_dir($controllerPath)) {
$files = scandir($controllerPath);
foreach ($files as $file) {
if (!empty($file) && substr_compare($file, 'Controller.php', -14) === 0) {
if (!empty($file) && substr_compare($file, 'Controller.php', -14, 14) === 0) {
$controllerClass = $module->controllerNamespace . '\\' . substr(basename($file), 0, -4);
if ($this->validateControllerClass($controllerClass)) {
$commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14));
......
......@@ -328,7 +328,7 @@ class MessageController extends Controller
ksort($existingMessages);
foreach ($existingMessages as $message => $translation) {
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) {
if (!empty($translation) && strncmp($translation, '@@', 2) === 0 && substr_compare($translation, '@@', -2) === 0) {
if (!empty($translation) && strncmp($translation, '@@', 2) === 0 && substr_compare($translation, '@@', -2, 2) === 0) {
$todo[$message] = $translation;
} else {
$todo[$message] = '@@' . $translation . '@@';
......
......@@ -65,7 +65,7 @@ class CheckboxColumn extends Column
if (empty($this->name)) {
throw new InvalidConfigException('The "name" property must be set.');
}
if (substr_compare($this->name, '[]', -2)) {
if (substr_compare($this->name, '[]', -2, 2)) {
$this->name .= '[]';
}
}
......
......@@ -785,13 +785,13 @@ class BaseHtml
if (!array_key_exists('size', $options)) {
$options['size'] = 4;
}
if (!empty($options['multiple']) && !empty($name) && substr_compare($name, '[]', -2)) {
if (!empty($options['multiple']) && !empty($name) && substr_compare($name, '[]', -2, 2)) {
$name .= '[]';
}
$options['name'] = $name;
if (isset($options['unselect'])) {
// add a hidden field so that if the list box has no option being selected, it still submits a value
if (!empty($name) && substr_compare($name, '[]', -2) === 0) {
if (!empty($name) && substr_compare($name, '[]', -2, 2) === 0) {
$name = substr($name, 0, -2);
}
$hidden = static::hiddenInput($name, $options['unselect']);
......
......@@ -204,7 +204,7 @@ abstract class Target extends Component
$matched = empty($categories);
foreach ($categories as $category) {
if ($message[2] === $category || !empty($category) && substr_compare($category, '*', -1) === 0 && strpos($message[2], rtrim($category, '*')) === 0) {
if ($message[2] === $category || !empty($category) && substr_compare($category, '*', -1, 1) === 0 && strpos($message[2], rtrim($category, '*')) === 0) {
$matched = true;
break;
}
......
......@@ -243,7 +243,7 @@ class UrlManager extends Component
$suffix = (string) $this->suffix;
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($this->suffix);
if (substr_compare($pathInfo, $this->suffix, -$n) === 0) {
if (substr_compare($pathInfo, $this->suffix, -$n, $n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
......
......@@ -219,7 +219,7 @@ class UrlRule extends Object implements UrlRuleInterface
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($suffix);
if (substr_compare($pathInfo, $suffix, -$n) === 0) {
if (substr_compare($pathInfo, $suffix, -$n, $n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment