Skip to content

Commit

Permalink
Ensure correct json default value normalization
Browse files Browse the repository at this point in the history
`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.

Fixes doctrine#6357
  • Loading branch information
sbuerk committed Apr 16, 2024
1 parent 16cfdc8 commit d0b5d6d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
- src/**
- tests/**
push:
branches:
- "*.x"
# branches:
# - "*.x"
paths:
- .github/workflows/continuous-integration.yml
- ci/**
Expand Down
1 change: 1 addition & 0 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$length = null;
break;

case 'json':
case 'text':
case '_varchar':
case 'varchar':
Expand Down
14 changes: 14 additions & 0 deletions tests/Functional/Schema/PostgreSQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,20 @@ public function testDefaultValueCharacterVarying(): void
self::assertEquals('foo', $databaseTable->getColumn('def')->getDefault());
}

public function testJsonDefaultValue(): void
{
$testTable = new Table('test_json');
$testTable
->addColumn('foo', Types::JSON)
->setDefault('{"key": "value with a single quote \' in string value"}');
$this->dropAndCreateTable($testTable);

$columns = $this->schemaManager->listTableColumns('test_json');

self::assertSame(Types::JSON, $columns['foo']->getType()->getName());
self::assertSame('{"key": "value with a single quote \' in string value"}', $columns['foo']->getDefault());
}

/**
* @param callable(AbstractSchemaManager):Comparator $comparatorFactory
*
Expand Down

0 comments on commit d0b5d6d

Please sign in to comment.