Browse Source

Fixes #15878: Fixed migration with a comment containing an apostrophe

tags/2.0.16
Marco Moreno 7 years ago committed by Alexander Makarov
parent
commit
c31f9ac811
  1. 2
      framework/CHANGELOG.md
  2. 5
      framework/db/mysql/QueryBuilder.php
  3. 5
      tests/framework/db/mysql/QueryBuilderTest.php

2
framework/CHANGELOG.md

@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.15 under development
------------------------
- no changes in this release.
- Bug #15878: Fixed migration with a comment containing an apostrophe (MarcoMoreno)
2.0.14.2 March 13, 2018

5
framework/db/mysql/QueryBuilder.php

@ -291,8 +291,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/
public function addCommentOnColumn($table, $column, $comment)
{
$definition = $this->getColumnDefinition($table, $column);
$definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition));
// Strip existing comment which may include escaped quotes
$definition = trim(preg_replace("/COMMENT '(?:''|[^'])*'/i", '',
$this->getColumnDefinition($table, $column)));
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' CHANGE ' . $this->db->quoteColumnName($column)

5
tests/framework/db/mysql/QueryBuilderTest.php

@ -64,6 +64,11 @@ class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest
$this->primaryKey()->comment('test')->after('col_before'),
"int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test' AFTER `col_before`",
],
[
Schema::TYPE_PK . " COMMENT 'testing \'quote\'' AFTER `col_before`",
$this->primaryKey()->comment('testing \'quote\'')->after('col_before'),
"int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'testing \'quote\'' AFTER `col_before`",
],
];
/*

Loading…
Cancel
Save