-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only first \0 is removed in comments, only first \\ is escaped e…
…tc. (#7532)
- Loading branch information
1 parent
daf3991
commit 36b14cb
Showing
10 changed files
with
168 additions
and
14 deletions.
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
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
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
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
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,53 @@ | ||
import {Column, Entity, PrimaryGeneratedColumn} from "../../../../src"; | ||
|
||
@Entity() | ||
export class Post { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ | ||
comment: `E.g. 'foo', 'bar', or 'baz' etc.` | ||
}) | ||
col1: string; | ||
|
||
@Column({ | ||
comment: `E.g. '''foo, 'bar''', or baz' etc.` | ||
}) | ||
col2: string; | ||
|
||
@Column({ | ||
comment: `E.g. "foo", "bar", or "baz" etc.` | ||
}) | ||
col3: string; | ||
|
||
@Column({ | ||
comment: "foo\\bar, bar\\baz, foo\\\\baz" | ||
}) | ||
col4: string; | ||
|
||
@Column({ | ||
comment: "foo: \0, bar: \0\0\0" | ||
}) | ||
col5: string; | ||
|
||
@Column({ | ||
comment: `"foo", ""bar""` | ||
}) | ||
col6: string; | ||
|
||
@Column({ | ||
comment: "\"foo\", \"\"bar\"\"" | ||
}) | ||
col7: string; | ||
|
||
@Column({ | ||
comment: "foo \r \n \b \t \Z \% \_ bar" | ||
}) | ||
col8: string; | ||
|
||
@Column({ | ||
comment: "foo \\r \\n \\b \\t \\Z \\% \\_ bar" | ||
}) | ||
col9: string; | ||
} |
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,55 @@ | ||
import "reflect-metadata"; | ||
import {Connection} from "../../../src"; | ||
import {createTestingConnections, closeTestingConnections} from "../../utils/test-utils"; | ||
import {Post} from "./entity/Post"; | ||
|
||
describe("github issues > #7521 Only first \0 is removed in comments, only first \\ is escaped etc.", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
enabledDrivers: ["postgres", "cockroachdb", "mysql"], | ||
schemaCreate: false, | ||
dropSchema: true, | ||
entities: [Post], | ||
})); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should recognize model changes", () => Promise.all(connections.map(async connection => { | ||
const sqlInMemory = await connection.driver.createSchemaBuilder().log(); | ||
sqlInMemory.upQueries.length.should.be.greaterThan(0); | ||
sqlInMemory.downQueries.length.should.be.greaterThan(0); | ||
}))); | ||
|
||
it("should not generate queries when no model changes", () => Promise.all(connections.map(async connection => { | ||
await connection.driver.createSchemaBuilder().build(); | ||
const sqlInMemory = await connection.driver.createSchemaBuilder().log(); | ||
sqlInMemory.upQueries.length.should.be.equal(0); | ||
sqlInMemory.downQueries.length.should.be.equal(0); | ||
}))); | ||
|
||
it("should properly escape quotes in comments", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
|
||
let table = await queryRunner.getTable("post"); | ||
const col1 = table!.findColumnByName("col1")!; | ||
const col2 = table!.findColumnByName("col2")!; | ||
const col3 = table!.findColumnByName("col3")!; | ||
const col4 = table!.findColumnByName("col4")!; | ||
const col5 = table!.findColumnByName("col5")!; | ||
const col6 = table!.findColumnByName("col6")!; | ||
const col7 = table!.findColumnByName("col7")!; | ||
const col8 = table!.findColumnByName("col8")!; | ||
const col9 = table!.findColumnByName("col9")!; | ||
|
||
col1.comment!.should.be.equal(`E.g. 'foo', 'bar', or 'baz' etc.`) | ||
col2.comment!.should.be.equal(`E.g. '''foo, 'bar''', or baz' etc.`) | ||
col3.comment!.should.be.equal(`E.g. "foo", "bar", or "baz" etc.`) | ||
col4.comment!.should.be.equal("foo\\bar, bar\\baz, foo\\\\baz") | ||
col5.comment!.should.be.equal(`foo: , bar: `) | ||
col6.comment!.should.be.equal(`"foo", ""bar""`) | ||
col7.comment!.should.be.equal("\"foo\", \"\"bar\"\"") | ||
col8.comment!.should.be.equal("foo \r \n \b \t \Z \% \_ bar") | ||
col9.comment!.should.be.equal("foo \\r \\n \\b \\t \\Z \\% \\_ bar") | ||
|
||
await queryRunner.release() | ||
}))); | ||
}); |