diff options
author | Phil Hughes <me@iamphill.com> | 2018-05-03 11:25:23 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-05-03 11:25:23 +0300 |
commit | 0108cdf95338f8807412e2b2672e8f4f161ebab4 (patch) | |
tree | aee43f3ffdfda3ad0a4a2d2ba7d0430315bcabff | |
parent | 6aad7b4941a2e35177b8e175c86bd3558e1a2b59 (diff) | |
parent | b12d6546afba081a1fd64877daaf30b68efba618 (diff) |
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
-rw-r--r-- | app/assets/javascripts/lib/utils/text_utility.js | 6 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/text_utility_spec.js | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/app/assets/javascripts/lib/utils/text_utility.js b/app/assets/javascripts/lib/utils/text_utility.js index b54ecd2d543..5e786ee6935 100644 --- a/app/assets/javascripts/lib/utils/text_utility.js +++ b/app/assets/javascripts/lib/utils/text_utility.js @@ -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 diff --git a/spec/javascripts/lib/utils/text_utility_spec.js b/spec/javascripts/lib/utils/text_utility_spec.js index ae00fb76714..eab5c24406a 100644 --- a/spec/javascripts/lib/utils/text_utility_spec.js +++ b/spec/javascripts/lib/utils/text_utility_spec.js @@ -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', () => { |