|
| 1 | +import "reflect-metadata"; |
| 2 | +import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; |
| 3 | +import {Connection} from "../../../src/connection/Connection"; |
| 4 | +import {Post} from "./entity/Post"; |
| 5 | + |
| 6 | +describe("github issues > #4719 HStore with empty string values", () => { |
| 7 | + let connections: Connection[]; |
| 8 | + before(async () => connections = await createTestingConnections({ |
| 9 | + entities: [__dirname + "/entity/*{.js,.ts}"], |
| 10 | + enabledDrivers: ["postgres"] |
| 11 | + })); |
| 12 | + beforeEach(() => reloadTestingDatabases(connections)); |
| 13 | + after(() => closeTestingConnections(connections)); |
| 14 | + |
| 15 | + it("should handle HStore with empty string keys or values", () => Promise.all(connections.map(async connection => { |
| 16 | + const queryRunner = connection.createQueryRunner(); |
| 17 | + const postRepository = connection.getRepository(Post); |
| 18 | + |
| 19 | + const post = new Post(); |
| 20 | + post.hstoreObj = {name: "Alice", surname: "A", age: 25, blank: "", "": "blank-key", "\"": "\"", foo: null}; |
| 21 | + const {id} = await postRepository.save(post); |
| 22 | + |
| 23 | + const loadedPost = await postRepository.findOneOrFail(id); |
| 24 | + loadedPost.hstoreObj.should.be.deep.equal( |
| 25 | + { name: "Alice", surname: "A", age: "25", blank: "", "": "blank-key", "\"": "\"", foo: null }); |
| 26 | + await queryRunner.release(); |
| 27 | + }))); |
| 28 | + |
| 29 | + it("should not allow 'hstore injection'", () => Promise.all(connections.map(async connection => { |
| 30 | + const queryRunner = connection.createQueryRunner(); |
| 31 | + const postRepository = connection.getRepository(Post); |
| 32 | + |
| 33 | + const post = new Post(); |
| 34 | + post.hstoreObj = { username: `", admin=>"1`, admin: "0" }; |
| 35 | + const {id} = await postRepository.save(post); |
| 36 | + |
| 37 | + const loadedPost = await postRepository.findOneOrFail(id); |
| 38 | + loadedPost.hstoreObj.should.be.deep.equal({ username: `", admin=>"1`, admin: "0" }); |
| 39 | + await queryRunner.release(); |
| 40 | + }))); |
| 41 | +}); |
0 commit comments