This repository was archived by the owner on Mar 18, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1636,7 +1636,7 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
16361636 c += " UNSIGNED" ;
16371637 }
16381638 if ( column . enum )
1639- c += ` (${ column . enum . map ( value => "'" + value + "'" ) . join ( ", " ) } )` ;
1639+ c += ` (${ column . enum . map ( value => "'" + value . replace ( "'" , "''" ) + "'" ) . join ( ", " ) } )` ;
16401640 if ( column . charset )
16411641 c += ` CHARACTER SET "${ column . charset } "` ;
16421642 if ( column . collation )
Original file line number Diff line number Diff line change @@ -1838,7 +1838,7 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
18381838 protected createEnumTypeSql ( table : Table , column : TableColumn , enumName ?: string ) : Query {
18391839 if ( ! enumName )
18401840 enumName = this . buildEnumName ( table , column ) ;
1841- const enumValues = column . enum ! . map ( value => `'${ value } '` ) . join ( ", " ) ;
1841+ const enumValues = column . enum ! . map ( value => `'${ value . replace ( "'" , "''" ) } '` ) . join ( ", " ) ;
18421842 return new Query ( `CREATE TYPE ${ enumName } AS ENUM(${ enumValues } )` ) ;
18431843 }
18441844
Original file line number Diff line number Diff line change 1+ import { Entity , Column , PrimaryGeneratedColumn } from "../../../../src" ;
2+
3+ export enum Realm {
4+ Blackrock = "Blackrock" ,
5+ KelThuzad = "Kel'Thuzad" ,
6+ }
7+
8+ @Entity ( )
9+ export class User {
10+ @PrimaryGeneratedColumn ( )
11+ id : number ;
12+
13+ @Column ( { type : "enum" , enum : Realm } )
14+ realm : Realm ;
15+ }
Original file line number Diff line number Diff line change 1+ import "reflect-metadata" ;
2+ import { createTestingConnections , closeTestingConnections , reloadTestingDatabases } from "../../utils/test-utils" ;
3+ import { Connection } from "../../../src/connection/Connection" ;
4+ import { Realm } from "./entity/User" ;
5+ import { User } from "./entity/User" ;
6+
7+ describe ( "github issues > #4630 Enum string not escaping resulting in broken migrations." , ( ) => {
8+
9+ let connections : Connection [ ] ;
10+ before ( async ( ) => connections = await createTestingConnections ( {
11+ entities : [ __dirname + "/entity/*{.js,.ts}" ] ,
12+ schemaCreate : true ,
13+ dropSchema : true ,
14+ enabledDrivers : [ "mysql" , "postgres" ]
15+ } ) ) ;
16+ beforeEach ( ( ) => reloadTestingDatabases ( connections ) ) ;
17+ after ( ( ) => closeTestingConnections ( connections ) ) ;
18+
19+ it ( "should support enums of strings with apostrophes in them" , ( ) => Promise . all ( connections . map ( async connection => {
20+ const user = new User ( ) ;
21+ user . realm = Realm . KelThuzad ;
22+
23+ await connection . manager . save ( user ) ;
24+
25+ const users = await connection . manager . find ( User ) ;
26+
27+ users . should . eql ( [ {
28+ id : 1 ,
29+ realm : "Kel'Thuzad"
30+ } ] ) ;
31+ } ) ) ) ;
32+ } ) ;
You can’t perform that action at this time.
0 commit comments