Remove backslash from search queries

Co-authored-by: Lee Randy <randy.lee@metronom.com>
Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>

See [#5053][0].

[0]: https://github.com/signalapp/Signal-Desktop/pull/5053
This commit is contained in:
rhklee 2021-04-02 22:29:54 +02:00 committed by GitHub
parent 901a54b149
commit 8b51f174d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1,13 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { cleanSearchTerm } from '../../util/cleanSearchTerm';
describe('cleanSearchTerm', () => {
it('should remove \\ from a search term', () => {
const searchTerm = '\\search\\term';
const sanitizedSearchTerm = cleanSearchTerm(searchTerm);
assert.strictEqual(sanitizedSearchTerm, 'search* term*');
});
});

View File

@ -4,7 +4,7 @@
export function cleanSearchTerm(searchTerm: string): string {
const lowercase = searchTerm.toLowerCase();
const withoutSpecialCharacters = lowercase.replace(
/([!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~])/g,
/([-!"#$%&'()*+,./\\:;<=>?@[\]^_`{|}~])/g,
' '
);
const whiteSpaceNormalized = withoutSpecialCharacters.replace(/\s+/g, ' ');