Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle enums with multiple apostrophes in MySQL (#8013)
Current implementation uses `"'"` in replace which only replaces first occurrence of `'`. Changing to `/'/g` will allow for all instances of apostrophes to be replaced. Closes: #8011
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src"; | ||
|
||
enum Category { | ||
MensAndWomensClothing = "Men's and Women's Clothing", | ||
Footwear = "Footwear", | ||
} | ||
|
||
@Entity() | ||
export class Example { | ||
@PrimaryGeneratedColumn("increment") | ||
id: number; | ||
|
||
@Column({ type: "enum", enum: Category }) | ||
category: Category; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import "reflect-metadata"; | ||
import { expect } from "chai"; | ||
import { Connection } from "../../../src"; | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils"; | ||
import { Example } from "./entity/Example"; | ||
|
||
describe("github issues > #8011 Enum values with multiple apostrophes not properly escaped in MySQL", () => { | ||
let connections: Connection[]; | ||
|
||
before(async () => { | ||
connections = await createTestingConnections({ | ||
enabledDrivers: ["mysql"], | ||
entities: [Example], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should properly escape all apostrophes", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
await connection.driver.createSchemaBuilder().build(); | ||
const sqlInMemory = await connection.driver | ||
.createSchemaBuilder() | ||
.log(); | ||
expect(sqlInMemory.upQueries.length).to.be.greaterThan(0); | ||
expect( | ||
sqlInMemory.upQueries.some(({ query }) => | ||
query.includes("Men''s and Women''s Clothing") | ||
) | ||
).to.be.true; | ||
}) | ||
)); | ||
}); |