Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape column comment in mysql driver #6056

Merged
merged 3 commits into from May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/driver/mysql/MysqlQueryRunner.ts
Expand Up @@ -1680,7 +1680,7 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
if (column.isGenerated && column.generationStrategy === "increment") // don't use skipPrimary here since updates can update already exist primary without auto inc.
c += " AUTO_INCREMENT";
if (column.comment)
c += ` COMMENT '${column.comment}'`;
c += ` COMMENT '${column.comment.replace("'", "''")}'`;
if (column.default !== undefined && column.default !== null)
c += ` DEFAULT ${column.default}`;
if (column.onUpdate)
Expand Down
11 changes: 11 additions & 0 deletions test/github-issues/6066/entity/Session.ts
@@ -0,0 +1,11 @@
import {Entity, PrimaryColumn} from "../../../../src";

@Entity()
export class Session {

@PrimaryColumn({
comment: "That's the way the cookie crumbles"
})
cookie: string = "";

}
22 changes: 22 additions & 0 deletions test/github-issues/6066/issue-6066.ts
@@ -0,0 +1,22 @@
import "reflect-metadata";
import {createTestingConnections, closeTestingConnections} from "../../utils/test-utils";
import {QueryFailedError, Connection} from "../../../src";
import {Session} from "./entity/Session";
import {expect} from "chai";

describe("github issues > #6066 Column comment string is not escaped during synchronization", () => {

let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [Session],
enabledDrivers: ["mysql", "mariadb"],
schemaCreate: false,
dropSchema: true,
}));
after(() => closeTestingConnections(connections));

it("should synchronize", () => Promise.all(connections.map(connection => {
return expect(connection.synchronize()).to.not.be.rejectedWith(QueryFailedError);
})));

});