diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index d74397f..f2b96e8 100644 --- a/framework/CHANGELOG.md +++ b/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 diff --git a/framework/db/mysql/QueryBuilder.php b/framework/db/mysql/QueryBuilder.php index ad5730e..491be25 100644 --- a/framework/db/mysql/QueryBuilder.php +++ b/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) diff --git a/tests/framework/db/mysql/QueryBuilderTest.php b/tests/framework/db/mysql/QueryBuilderTest.php index ad0edd2..997f7db 100644 --- a/tests/framework/db/mysql/QueryBuilderTest.php +++ b/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`", + ], ]; /*