Skip to content

Commit 5fc802d

Browse files
authored
fix: escape column comment in mysql driver (#6056)
* Fixed bug with unescaped comment string in MySQL driver. * Added tests. * Fixed linting issue.
1 parent 8e0d817 commit 5fc802d

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/driver/mysql/MysqlQueryRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
16801680
if (column.isGenerated && column.generationStrategy === "increment") // don't use skipPrimary here since updates can update already exist primary without auto inc.
16811681
c += " AUTO_INCREMENT";
16821682
if (column.comment)
1683-
c += ` COMMENT '${column.comment}'`;
1683+
c += ` COMMENT '${column.comment.replace("'", "''")}'`;
16841684
if (column.default !== undefined && column.default !== null)
16851685
c += ` DEFAULT ${column.default}`;
16861686
if (column.onUpdate)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Entity, PrimaryColumn} from "../../../../src";
2+
3+
@Entity()
4+
export class Session {
5+
6+
@PrimaryColumn({
7+
comment: "That's the way the cookie crumbles"
8+
})
9+
cookie: string = "";
10+
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import "reflect-metadata";
2+
import {createTestingConnections, closeTestingConnections} from "../../utils/test-utils";
3+
import {QueryFailedError, Connection} from "../../../src";
4+
import {Session} from "./entity/Session";
5+
import {expect} from "chai";
6+
7+
describe("github issues > #6066 Column comment string is not escaped during synchronization", () => {
8+
9+
let connections: Connection[];
10+
before(async () => connections = await createTestingConnections({
11+
entities: [Session],
12+
enabledDrivers: ["mysql", "mariadb"],
13+
schemaCreate: false,
14+
dropSchema: true,
15+
}));
16+
after(() => closeTestingConnections(connections));
17+
18+
it("should synchronize", () => Promise.all(connections.map(connection => {
19+
return expect(connection.synchronize()).to.not.be.rejectedWith(QueryFailedError);
20+
})));
21+
22+
});

0 commit comments

Comments
 (0)