Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow periods in parameter identifiers (#8022)
updates the character set for parameter identifiers to include periods. also update the `setParameter` function on query builder to validate these identifiers to ensure have explicit failures when invalid keys are used
- Loading branch information
1 parent
768b4fe
commit 4201938
Showing
11 changed files
with
74 additions
and
8 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
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,7 @@ | ||
import { Entity, PrimaryColumn } from "../../../../../src"; | ||
|
||
@Entity() | ||
export class Example { | ||
@PrimaryColumn() | ||
id: string | ||
} |
53 changes: 53 additions & 0 deletions
53
test/functional/query-builder/parameters/query-builder-parameters.ts
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 "reflect-metadata"; | ||
import { Example } from "./entity/Example"; | ||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils"; | ||
import {expect} from "chai"; | ||
import { Connection } from "../../../../src"; | ||
|
||
describe("query builder > parameters", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [ Example ], | ||
enabledDrivers: [ "sqlite" ] | ||
|
||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should replace basic parameters when executing", () => Promise.all(connections.map(async connection => { | ||
const repo = connection.getRepository(Example); | ||
|
||
await repo.save({ id: 'bar' }); | ||
|
||
const example = await repo.createQueryBuilder() | ||
.setParameter('foo', 'bar') | ||
.where('example.id = :foo') | ||
.getOne(); | ||
|
||
expect(example?.id).to.be.equal('bar') | ||
}))) | ||
|
||
it("should prevent invalid characters from being used as identifiers", () => Promise.all(connections.map(async connection => { | ||
const b = connection.createQueryBuilder(); | ||
|
||
expect(() => b.setParameter(':foo', 'bar')).to.throw(); | ||
expect(() => b.setParameter('@foo', 'bar')).to.throw(); | ||
expect(() => b.setParameter('😋', 'bar')).to.throw(); | ||
expect(() => b.setParameter('foo bar', 'bar')).to.throw(); | ||
}))) | ||
|
||
it("should allow periods in parameters", () => Promise.all(connections.map(async connection => { | ||
const repo = connection.getRepository(Example); | ||
|
||
await repo.save({ id: 'bar' }); | ||
|
||
const example = await repo.createQueryBuilder() | ||
.setParameter('f.o.o', 'bar') | ||
.where('example.id = :f.o.o') | ||
.getOne(); | ||
|
||
expect(example?.id).to.be.equal('bar') | ||
}))) | ||
|
||
}); |