diff --git a/lib/strip_html.js b/lib/strip_html.js index 4c4618ad..12bde087 100644 --- a/lib/strip_html.js +++ b/lib/strip_html.js @@ -5,6 +5,11 @@ const STATE_HTML = Symbol('html'); const STATE_COMMENT = Symbol('comment'); function striptags(html = '') { + // if not string, then safely return an empty string + if (typeof html !== 'string' && !(html instanceof String)) { + return ''; + } + let state = STATE_PLAINTEXT; let tag_buffer = ''; let depth = 0; diff --git a/test/strip_html.spec.js b/test/strip_html.spec.js index 78336b7d..0ac66317 100644 --- a/test/strip_html.spec.js +++ b/test/strip_html.spec.js @@ -51,4 +51,11 @@ describe('stripHTML', () => { stripHTML(html).should.eql(text); }); + + it('should strip non string parameters', () => { + const html = ['X']; + const text = ''; + + stripHTML(html).should.eql(text); + }); });