Skip to content
Snippets Groups Projects
Commit 0108cdf9 authored by Phil Hughes's avatar Phil Hughes
Browse files

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
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