Skip to content

Commit

Permalink
fix(stripHTML): should be more strict with non string (#265)
Browse files Browse the repository at this point in the history
And strip them :)
  • Loading branch information
tomap committed Nov 7, 2021
1 parent ce27f06 commit dd530da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/strip_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/strip_html.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit dd530da

Please sign in to comment.