Skip to content

Commit e2a6621

Browse files
authored
Ensure correct json default value normalization (#6358)
<!-- Fill in the relevant information below to help triage your pull request. --> | Q | A |------------- | ----------- | Type | bug | Fixed issues | #6357 #### Summary `PostgreSQLSchemaManager::_getPortableTableColumnDefinition()` is modified to call the private method `parseDefaultExpression()` on default values for `JSON` field to correctly normalize doubled single-quotes in json string value. A test to cover this case is added.
1 parent 16cfdc8 commit e2a6621

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Schema/PostgreSQLSchemaManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
463463
$length = null;
464464
break;
465465

466+
case 'json':
466467
case 'text':
467468
case '_varchar':
468469
case 'varchar':

tests/Functional/Schema/PostgreSQLSchemaManagerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,20 @@ public function testDefaultValueCharacterVarying(): void
300300
self::assertEquals('foo', $databaseTable->getColumn('def')->getDefault());
301301
}
302302

303+
public function testJsonDefaultValue(): void
304+
{
305+
$testTable = new Table('test_json');
306+
$testTable
307+
->addColumn('foo', Types::JSON)
308+
->setDefault('{"key": "value with a single quote \' in string value"}');
309+
$this->dropAndCreateTable($testTable);
310+
311+
$columns = $this->schemaManager->listTableColumns('test_json');
312+
313+
self::assertSame(Types::JSON, $columns['foo']->getType()->getName());
314+
self::assertSame('{"key": "value with a single quote \' in string value"}', $columns['foo']->getDefault());
315+
}
316+
303317
/**
304318
* @param callable(AbstractSchemaManager):Comparator $comparatorFactory
305319
*

0 commit comments

Comments
 (0)