Skip to content

Commit 5c5f3b0

Browse files
authored
Fix issue with empty string values in ENUM parsing for MySQL columns (#92)
1 parent 00b2a98 commit 5c5f3b0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Tokenizers/BaseTokenizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(string $value)
3333
}
3434
}
3535

36-
if (preg_match_all("/'(.+?)'/", $value, $matches)) {
36+
if (preg_match_all("/'(.*?)'/", $value, $matches)) {
3737
foreach ($matches[0] as $quoteWithSpace) {
3838
//we've got an enum or set that has spaces in the text
3939
//so we'll convert to a different character so it doesn't get pruned

tests/Unit/Tokenizers/MySQL/ColumnTokenizerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,14 @@ public function test_it_tokenizes_enum_with_special_characters()
922922
$this->assertEquals('$table->enum(\'calculate\', [\'one\', \'and\', \'highest-or\', \'lowest^or\', \'sum%\', \'highest $ position or\', \'lowest+_<>?/ position or\', \'"quoted"\'])->comment("set the way we calculate a feature value. with high or low or the sort is by position")', $definition->render());
923923
}
924924

925+
public function test_it_tokenizes_enum_with_empty_string()
926+
{
927+
$columnTokenizer = ColumnTokenizer::parse('`text` enum(\'\',\'not-empty-string\',\'string with spaces\') DEFAULT \'\'');
928+
$definition = $columnTokenizer->definition();
929+
930+
$this->assertEquals('$table->enum(\'text\', [\'\', \'not-empty-string\', \'string with spaces\'])->default(\'\')', $definition->render());
931+
}
932+
925933
//endregion
926934

927935
//region POINT, MULTIPOINT

0 commit comments

Comments
 (0)