Skip to content

Commit

Permalink
Fix Incomplete multi-character sanitization in stripHtml function
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmybtlr committed May 15, 2024
1 parent 5dccf23 commit 23fc860
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/modifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as mod from './modifiers'

test('stripHtml', () => {
expect(mod.stripHtml('<p>Hello world</p>')).toBe('Hello world')
expect(mod.stripHtml('<script>Hello world</script>')).toBe('Hello world')
})

test('escapeHtml', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function ordinalize(value: number): string {
* Strip HTML tags from a string.
*/
export function stripHtml(text: string): string {
return text.replace(/<[^>]*>/gm, '')
return text.replace(/<\/?[^>]+(>|$)/g, '')
}

/**
Expand Down

0 comments on commit 23fc860

Please sign in to comment.