Skip to content
Snippets Groups Projects
Commit b12d6546 authored by Olivier Gonzalez's avatar Olivier Gonzalez Committed by Phil Hughes
Browse files

Add pass through to stripHtml for undefined and null inputs

parent 6aad7b49
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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', () => {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment