-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: "hstore injection" & properly handle NULL, empty string, backsla…
…shes & quotes in hstore key/value pairs (#4720) * Improve HStore object support * Add hstore-injection test
- Loading branch information
1 parent
644c21b
commit 3abe5b9
Showing
3 changed files
with
71 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Column, Entity, PrimaryGeneratedColumn, ObjectLiteral} from "../../../../src/index"; | ||
|
||
@Entity() | ||
export class Post { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column("hstore", { hstoreType: "object" }) | ||
hstoreObj: ObjectLiteral; | ||
|
||
} |
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,41 @@ | ||
import "reflect-metadata"; | ||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
import {Connection} from "../../../src/connection/Connection"; | ||
import {Post} from "./entity/Post"; | ||
|
||
describe("github issues > #4719 HStore with empty string values", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["postgres"] | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should handle HStore with empty string keys or values", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
const postRepository = connection.getRepository(Post); | ||
|
||
const post = new Post(); | ||
post.hstoreObj = {name: "Alice", surname: "A", age: 25, blank: "", "": "blank-key", "\"": "\"", foo: null}; | ||
const {id} = await postRepository.save(post); | ||
|
||
const loadedPost = await postRepository.findOneOrFail(id); | ||
loadedPost.hstoreObj.should.be.deep.equal( | ||
{ name: "Alice", surname: "A", age: "25", blank: "", "": "blank-key", "\"": "\"", foo: null }); | ||
await queryRunner.release(); | ||
}))); | ||
|
||
it("should not allow 'hstore injection'", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
const postRepository = connection.getRepository(Post); | ||
|
||
const post = new Post(); | ||
post.hstoreObj = { username: `", admin=>"1`, admin: "0" }; | ||
const {id} = await postRepository.save(post); | ||
|
||
const loadedPost = await postRepository.findOneOrFail(id); | ||
loadedPost.hstoreObj.should.be.deep.equal({ username: `", admin=>"1`, admin: "0" }); | ||
await queryRunner.release(); | ||
}))); | ||
}); |