Skip to content

Commit

Permalink
fix: escape column comment in mysql driver (#6056)
Browse files Browse the repository at this point in the history
* Fixed bug with unescaped comment string in MySQL driver.

* Added tests.

* Fixed linting issue.
  • Loading branch information
BTOdell committed May 15, 2020
1 parent 8e0d817 commit 5fc802d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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);
})));

});

0 comments on commit 5fc802d

Please sign in to comment.