Skip to content

Commit

Permalink
fix: scrub all comment end markers from comments (#10163)
Browse files Browse the repository at this point in the history
This was only removing the first comment end marker, so it was still
possible to generate invalid SQL with the comment method.
  • Loading branch information
smcgivern committed Aug 19, 2023
1 parent 9f8899f commit d937f61
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/query-builder/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ export abstract class QueryBuilder<Entity extends ObjectLiteral> {
// to scrub "ending" characters from the SQL but otherwise we can leave everything else
// as-is and it should be valid.

return `/* ${this.expressionMap.comment.replace("*/", "")} */ `
return `/* ${this.expressionMap.comment.replace(/\*\//g, "")} */ `
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ describe("query builder > comment", () => {
connections.map(async (connection) => {
const sql = connection.manager
.createQueryBuilder(Test, "test")
.comment("Hello World */")
.comment("Hello World */ */")
.getSql()

expect(sql).to.match(/^\/\* Hello World \*\/ /)
expect(sql).to.match(/^\/\* Hello World \*\/ /)
}),
))

Expand Down

0 comments on commit d937f61

Please sign in to comment.