Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stripHTML should be more strict with non string #265

Merged
merged 1 commit into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});