From 23fc8600a1729e69c3a0c582dfdb65c641bdc218 Mon Sep 17 00:00:00 2001 From: Jeremy Butler Date: Wed, 15 May 2024 19:28:55 +1000 Subject: [PATCH] Fix Incomplete multi-character sanitization in stripHtml function --- src/modifiers.test.ts | 1 + src/modifiers.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modifiers.test.ts b/src/modifiers.test.ts index 86e5befe..03531432 100644 --- a/src/modifiers.test.ts +++ b/src/modifiers.test.ts @@ -3,6 +3,7 @@ import * as mod from './modifiers' test('stripHtml', () => { expect(mod.stripHtml('

Hello world

')).toBe('Hello world') + expect(mod.stripHtml('')).toBe('Hello world') }) test('escapeHtml', () => { diff --git a/src/modifiers.ts b/src/modifiers.ts index 9082f82e..3f4d45e4 100644 --- a/src/modifiers.ts +++ b/src/modifiers.ts @@ -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, '') } /**