-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(postgres): escape array literal values containing backslash (#4797)
Closes #4796
- Loading branch information
1 parent
afba990
commit 20179ec
Showing
2 changed files
with
56 additions
and
1 deletion.
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,55 @@ | ||
import { | ||
Entity, | ||
OptionalProps, | ||
PrimaryKey, | ||
Property, | ||
SimpleLogger, | ||
} from '@mikro-orm/core'; | ||
import { MikroORM } from '@mikro-orm/postgresql'; | ||
import { mockLogger } from '../helpers'; | ||
|
||
@Entity() | ||
class User { | ||
|
||
[OptionalProps]?: 'options'; | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@Property({ type: 'string[]', default: ['foo'] }) | ||
options = ['foo']; | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [User], | ||
dbName: 'mikro_orm_test_gh_4796', | ||
loggerFactory: options => new SimpleLogger(options), | ||
}); | ||
await orm.schema.refreshDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await orm.close(); | ||
}); | ||
|
||
test('4796', async () => { | ||
const mock = mockLogger(orm, ['query', 'query-params']); | ||
const u1 = orm.em.create(User, { options: ['\\'] }); | ||
await orm.em.flush(); | ||
|
||
expect(mock.mock.calls).toEqual([ | ||
['[query] begin'], | ||
[ | ||
'[query] insert into "user" ("options") values ( E\'{"\\\\\\\\"}\') returning "id", "options"', | ||
], | ||
['[query] commit'], | ||
]); | ||
|
||
const ud = await orm.em.fork().findOne(User, { id: u1.id }); | ||
|
||
expect(ud).toEqual({ id: 1, options: ['\\'] }); | ||
}); |