You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Updating full text fields with values containing multiple question marks is producing incorrect SQL. It seems the first question mark is being escaped, but additional ones are not.
Stack trace
console.log
[query] update "book" set "title" = 'My Life on The ? Wall, part ? ?', "searchable_title" = to_tsvector('simple', 'My Life on The ? Wall, part 1 NULL') where "id" = NULL [took 1 ms]
at DefaultLogger.log (packages/core/src/logging/DefaultLogger.ts:34:10)
To Reproduce
Steps to reproduce the behavior:
add the following test to tests/features/fulltext/full-text-search-tsvector.postgres.test.ts
test('update entity', async () => {
const repo = orm.em.getRepository(Book);
const book1 = new Book('My Life on The Wall');
repo.create(book1);
await repo.flush();
const newTitle = 'My Life on The ? Wall, part ? ?';
book1.title = newTitle;
await repo.flush();
repo.getEntityManager().clear();
const reloadedBook = await repo.findOne({ id: book1.id });
expect(reloadedBook?.title).toBe(newTitle);
});
Expected behavior
The provided test to pass. Every ? should be handled correctly, not just the first one. The generated SQL should look like:
console.log
[query] update "book" set "title" = 'My Life on The ? Wall, part ? ?', "searchable_title" = to_tsvector('simple', 'My Life on The ? Wall, part ? ?') where "id" = 1 [took 1 ms]
at DefaultLogger.log (packages/core/src/logging/DefaultLogger.ts:34:10)
Additional context
Seems like the same issue described in #3457 but regarding multiple instances of ?.
Looking at the solution for that issue, a replacement for the first occurrence of ? was added in packages/knex/src/query/QueryBuilderHelper.ts
Seems like using a global regexp in QueryBuilderHelper.ts fixes the issue: sql.replace(/\?/g, '\\?')
Versions
Dependency
Version
node
v18.15.0
typescript
5.1.3
mikro-orm
5.7.12
@mikro-orm/postgresql
5.7.12
The text was updated successfully, but these errors were encountered:
Describe the bug
Updating full text fields with values containing multiple question marks is producing incorrect SQL. It seems the first question mark is being escaped, but additional ones are not.
Stack trace
To Reproduce
Steps to reproduce the behavior:
tests/features/fulltext/full-text-search-tsvector.postgres.test.ts
Expected behavior
The provided test to pass. Every
?
should be handled correctly, not just the first one. The generated SQL should look like:Additional context
Seems like the same issue described in #3457 but regarding multiple instances of
?
.Looking at the solution for that issue, a replacement for the first occurrence of
?
was added inpackages/knex/src/query/QueryBuilderHelper.ts
Seems like using a global regexp in
QueryBuilderHelper.ts
fixes the issue:sql.replace(/\?/g, '\\?')
Versions
The text was updated successfully, but these errors were encountered: