Skip to content

Commit dd530da

Browse files
authored
fix(stripHTML): should be more strict with non string (#265)
And strip them :)
1 parent ce27f06 commit dd530da

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/strip_html.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const STATE_HTML = Symbol('html');
55
const STATE_COMMENT = Symbol('comment');
66

77
function striptags(html = '') {
8+
// if not string, then safely return an empty string
9+
if (typeof html !== 'string' && !(html instanceof String)) {
10+
return '';
11+
}
12+
813
let state = STATE_PLAINTEXT;
914
let tag_buffer = '';
1015
let depth = 0;

test/strip_html.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,11 @@ describe('stripHTML', () => {
5151

5252
stripHTML(html).should.eql(text);
5353
});
54+
55+
it('should strip non string parameters', () => {
56+
const html = ['X'];
57+
const text = '';
58+
59+
stripHTML(html).should.eql(text);
60+
});
5461
});

0 commit comments

Comments
 (0)