1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Use replace instead of replace all so that we are compatible with v78 (#18080)

* Use replace instead of replace all so that we are compatible with v78

* Add unit tests
This commit is contained in:
Dan J Miller 2023-03-10 05:36:07 -08:00 committed by PeterYinusa
parent 535d55ea8b
commit 150f0ee766
2 changed files with 25 additions and 1 deletions

View File

@ -560,5 +560,5 @@ export const sanitizeString = (value) => {
return value;
}
const regex = /\u202E/giu;
return value.replaceAll(regex, '\\u202E');
return value.replace(regex, '\\u202E');
};

View File

@ -565,4 +565,28 @@ describe('util', () => {
expect(result.do_not_display_2).toBeUndefined();
});
});
describe('sanitizeString', () => {
it('should return the passed value, unchanged, if it is falsy', () => {
expect(util.sanitizeString('')).toStrictEqual('');
});
it('should return the passed value, unchanged, if it is not a string', () => {
expect(util.sanitizeString(true)).toStrictEqual(true);
});
it('should return a truthy string that oes not match the sanitizeString regex, unchanged', () => {
expect(
util.sanitizeString('The Quick Brown Fox Jumps Over The Lazy Dog'),
).toStrictEqual('The Quick Brown Fox Jumps Over The Lazy Dog');
});
it('should return a string that matches sanitizeString regex with the matched characters replaced', () => {
expect(
util.sanitizeString(
'The Quick Brown \u202EFox Jumps Over The Lazy Dog',
),
).toStrictEqual('The Quick Brown \\u202EFox Jumps Over The Lazy Dog');
});
});
});