diff --git a/src/Schema.php b/src/Schema.php index 1ddfab06..2532b1b8 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -771,8 +771,8 @@ private function findComments(TableSchemaInterface $tableSchema): void $columnsDefinition = $matches[1]; - $identifierPattern = '(?:([`"])([^`"]+)\1|\[([^\]]+)\]|([A-Za-z_]\w*))'; - $notCommaPattern = '(?:[^,]|\([^()]+\))*?'; + $identifierPattern = '(?:([`"])([^`"]+)\1|\[([^\]]+)\]|([a-zA-Z_]\w*))'; + $notCommaPattern = "(?:[^,]|\([^()]+\)|'[^']+')*?"; $commentPattern = '(?:\s*--[^\n]*|\s*/\*.*?\*/)'; $pattern = "#$identifierPattern\s*$notCommaPattern,?($commentPattern+)#"; diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index ca2f5484..071c2740 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -376,6 +376,7 @@ public function testColumnComments(): void $table = $schema->getTableSchema('comment'); $this->assertSame('primary key', $table->getColumn('id')->getComment()); + $this->assertSame('USD', $table->getColumn('price')->getComment()); $this->assertSame("Column comment\nsecond line\nthird line", $table->getColumn('name')->getComment()); } } diff --git a/tests/Support/Fixture/sqlite.sql b/tests/Support/Fixture/sqlite.sql index d38ed56e..90879882 100644 --- a/tests/Support/Fixture/sqlite.sql +++ b/tests/Support/Fixture/sqlite.sql @@ -179,7 +179,8 @@ CREATE TABLE `comment` -- Table comment /* third line */ ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, -- primary key - `name` varchar(100) -- Column comment + price decimal(10,2), -- USD + `name` varchar(100) DEFAULT 'Pan, Peter' -- Column comment -- second line /* third line */ );