fix: Search query backslash replacement only touched first instance

closes #2111
This commit is contained in:
Tom Moor
2021-05-12 20:27:14 -07:00
parent 9d03c89c02
commit 3bd56fff9e
2 changed files with 7 additions and 1 deletions

View File

@@ -248,7 +248,7 @@ type SearchOptions = {
function escape(query: string): string {
// replace "\" with escaped "\\" because sequelize.escape doesn't do it
// https://github.com/sequelize/sequelize/issues/2950
return sequelize.escape(query).replace("\\", "\\\\");
return sequelize.escape(query).replace(/\\/g, "\\\\");
}
Document.searchForTeam = async (

View File

@@ -197,6 +197,12 @@ describe("#searchForTeam", () => {
expect(results.length).toBe(0);
});
test("should handle backslashes in search term", async () => {
const team = await buildTeam();
const { results } = await Document.searchForTeam(team, "\\\\");
expect(results.length).toBe(0);
});
test("should return the total count of search results", async () => {
const team = await buildTeam();
const collection = await buildCollection({ teamId: team.id });