diff --git a/app/lib/database/utils.js b/app/lib/database/utils.js index 6c5d86b5e..472af733b 100644 --- a/app/lib/database/utils.js +++ b/app/lib/database/utils.js @@ -2,6 +2,6 @@ import XRegExp from 'xregexp'; // Matches letters from any alphabet and numbers const likeStringRegex = new XRegExp('[^\\p{L}\\p{Nd}]', 'g'); -export const sanitizeLikeString = str => str.replace(likeStringRegex, '_'); +export const sanitizeLikeString = str => str?.replace(likeStringRegex, '_'); export const sanitizer = r => r; diff --git a/app/lib/database/utils.test.js b/app/lib/database/utils.test.js index dd1e3996e..cbeae7b8a 100644 --- a/app/lib/database/utils.test.js +++ b/app/lib/database/utils.test.js @@ -4,9 +4,14 @@ import * as utils from './utils'; describe('sanitizeLikeStringTester', () => { // example chars that shouldn't return const disallowedChars = ',./;[]!@#$%^&*()_-=+~'; - const sanitizeLikeStringTester = str => expect(utils.sanitizeLikeString(`${ str }${ disallowedChars }`)).toBe(`${ str }${ '_'.repeat(disallowedChars.length) }`); + test('render empty', () => { + expect(utils.sanitizeLikeString(null)).toBe(undefined); + expect(utils.sanitizeLikeString('')).toBe(''); + expect(utils.sanitizeLikeString(undefined)).toBe(undefined); + }); + // Testing a couple of different alphabets test('render test (latin)', () => { sanitizeLikeStringTester('test123');