Commit 0108cdf9 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'add_pass_through_to_strip_html_utility' into 'master'

Add pass through to stripHtml for undefined and null inputs

See merge request gitlab-org/gitlab-ce!18690
parents 6aad7b49 b12d6546
......@@ -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
......
......@@ -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', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment