Skip to content

Commit

Permalink
fix: stripTags shouldn't throw with null/undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Dec 9, 2023
1 parent 05361e7 commit 8f706fc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
8 changes: 0 additions & 8 deletions packages/utils/src/__tests__/stripTagsUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,5 @@ describe('stripTags()', () => {
it('should throw when input is not a string neither a number', () => {
expect(() => stripTags(['type-confusion'] as any)).toThrow(`'html' parameter must be a string`);
});

it('should throw when input is undefined', () => {
expect(() => stripTags(undefined as any)).toThrow(`'html' parameter must be a string`);
});

it('should throw when input is null', () => {
expect(() => stripTags(null as any)).toThrow(`'html' parameter must be a string`);
});
});
});
2 changes: 1 addition & 1 deletion packages/utils/src/stripTagsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function stripTags(htmlText: string | number | boolean | HTMLElement, all
if (html instanceof HTMLElement) {
html = html.innerHTML;
}
if (typeof html !== 'string' && html !== undefined) {
if (typeof html !== 'string' && html !== undefined && html !== null) {
throw new TypeError(`'html' parameter must be a string`);
}

Expand Down

0 comments on commit 8f706fc

Please sign in to comment.