[FIX] SanitizeLikeString util crashes for empty strings (#2471)
This commit is contained in:
parent
7b67ae4757
commit
fb3e8bc203
|
@ -2,6 +2,6 @@ import XRegExp from 'xregexp';
|
||||||
|
|
||||||
// Matches letters from any alphabet and numbers
|
// Matches letters from any alphabet and numbers
|
||||||
const likeStringRegex = new XRegExp('[^\\p{L}\\p{Nd}]', 'g');
|
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;
|
export const sanitizer = r => r;
|
||||||
|
|
|
@ -4,9 +4,14 @@ import * as utils from './utils';
|
||||||
describe('sanitizeLikeStringTester', () => {
|
describe('sanitizeLikeStringTester', () => {
|
||||||
// example chars that shouldn't return
|
// example chars that shouldn't return
|
||||||
const disallowedChars = ',./;[]!@#$%^&*()_-=+~';
|
const disallowedChars = ',./;[]!@#$%^&*()_-=+~';
|
||||||
|
|
||||||
const sanitizeLikeStringTester = str => expect(utils.sanitizeLikeString(`${ str }${ disallowedChars }`)).toBe(`${ str }${ '_'.repeat(disallowedChars.length) }`);
|
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
|
// Testing a couple of different alphabets
|
||||||
test('render test (latin)', () => {
|
test('render test (latin)', () => {
|
||||||
sanitizeLikeStringTester('test123');
|
sanitizeLikeStringTester('test123');
|
||||||
|
|
Loading…
Reference in New Issue