Add pass through to stripHtml for undefined and null inputs

This commit is contained in:
Olivier Gonzalez 2018-05-03 08:25:22 +00:00 committed by Phil Hughes
parent 6aad7b4941
commit b12d6546af
2 changed files with 13 additions and 1 deletions

View File

@ -74,7 +74,11 @@ export function capitalizeFirstCharacter(text) {
* @param {*} replace
* @returns {String}
*/
export const stripHtml = (string, replace = '') => string.replace(/<[^>]*>/g, replace);
export const stripHtml = (string, replace = '') => {
if (!string) return string;
return string.replace(/<[^>]*>/g, replace);
};
/**
* Converts snake_case string to camelCase

View File

@ -75,6 +75,14 @@ describe('text_utility', () => {
'This is a text with html .',
);
});
it('passes through with null string input', () => {
expect(textUtils.stripHtml(null, ' ')).toEqual(null);
});
it('passes through with undefined string input', () => {
expect(textUtils.stripHtml(undefined, ' ')).toEqual(undefined);
});
});
describe('convertToCamelCase', () => {