diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index e033bd5d3f07255dab6c77bfd6d28afe00017903..10a01f42d6d6a32885a81ef35fee992e4d0d477d 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -13,6 +13,7 @@ use Drupal\Core\Database\SchemaObjectExistsException; use Drupal\Core\Database\SchemaObjectDoesNotExistException; use Drupal\Core\Database\Schema as DatabaseSchema; +use Drupal\Component\Utility\Unicode; /** * @addtogroup schemaapi @@ -492,7 +493,7 @@ public function prepareComment($comment, $length = NULL) { // Truncate comment to maximum comment length. if (isset($length)) { // Add table prefixes before truncating. - $comment = substr($this->connection->prefixTables($comment), 0, $length); + $comment = Unicode::truncate($this->connection->prefixTables($comment), $length, TRUE, TRUE); } return $this->connection->quote($comment); diff --git a/core/modules/system/src/Tests/Database/SchemaTest.php b/core/modules/system/src/Tests/Database/SchemaTest.php index 026455655cbe6058b3db92ec5ca07b36d5886dc8..0a4437545095e6474a650736fa8da7b32778c504 100644 --- a/core/modules/system/src/Tests/Database/SchemaTest.php +++ b/core/modules/system/src/Tests/Database/SchemaTest.php @@ -11,6 +11,7 @@ use Drupal\Core\Database\SchemaObjectDoesNotExistException; use Drupal\Core\Database\SchemaObjectExistsException; use Drupal\simpletest\KernelTestBase; +use Drupal\Component\Utility\Unicode; /** * Tests table creation and modification via the schema API. @@ -30,7 +31,7 @@ class SchemaTest extends KernelTestBase { function testSchema() { // Try creating a table. $table_specification = array( - 'description' => 'Schema table description.', + 'description' => 'Schema table description may contain "quotes" and could be long—very long indeed.', 'fields' => array( 'id' => array( 'type' => 'int', @@ -39,7 +40,7 @@ function testSchema() { 'test_field' => array( 'type' => 'int', 'not null' => TRUE, - 'description' => 'Schema column description.', + 'description' => 'Schema table description may contain "quotes" and could be long—very long indeed. There could be "multiple quoted regions".', ), 'test_field_string' => array( 'type' => 'varchar', @@ -212,6 +213,11 @@ function tryInsert($table = 'test_table') { function checkSchemaComment($description, $table, $column = NULL) { if (method_exists(Database::getConnection()->schema(), 'getComment')) { $comment = Database::getConnection()->schema()->getComment($table, $column); + // The schema comment truncation for mysql is different. + if (Database::getConnection()->databaseType() == 'mysql') { + $max_length = $column ? 255 : 60; + $description = Unicode::truncate($description, $max_length, TRUE, TRUE); + } $this->assertEqual($comment, $description, 'The comment matches the schema description.'); } }