Skip to content

Commit 4e90385

Browse files
committed
feat: more esacpe
1 parent a40d46b commit 4e90385

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

libraries/helpers/src/utils/strip.html.validation.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,13 @@ export const stripHtmlValidation = (
156156
'strong',
157157
'u',
158158
'a',
159-
]);
159+
])
160+
.replace(/>/gi, '>')
161+
.replace(/&lt;/gi, '<')
162+
.replace(/&amp;/gi, '&')
163+
.replace(/&nbsp;/gi, ' ')
164+
.replace(/&quot;/gi, '"')
165+
.replace(/&#39;/gi, "'");
160166
}
161167

162168
if (type === 'markdown') {
@@ -168,6 +174,8 @@ export const stripHtmlValidation = (
168174
})
169175
.replace(/&amp;/gi, '&')
170176
.replace(/&nbsp;/gi, ' ')
177+
.replace(/&quot;/gi, '"')
178+
.replace(/&#39;/gi, "'")
171179
.replace(/<h2>([.\s\S]*?)<\/h2>/g, (match, p1) => {
172180
return `<h2>## ${p1}</h2>\n`;
173181
})
@@ -206,14 +214,14 @@ export const stripHtmlValidation = (
206214
const html = (value || '')
207215
.replace(/&amp;/gi, '&')
208216
.replace(/&nbsp;/gi, ' ')
217+
.replace(/&quot;/gi, '"')
218+
.replace(/&#39;/gi, "'")
209219
.replace(/^<p[^>]*>/i, '')
210220
.replace(/<p[^>]*>/gi, '\n')
211-
.replace(/<\/p>/gi, '')
212-
.replace(/&gt;/gi, '>')
213-
.replace(/&lt;/gi, '<');
221+
.replace(/<\/p>/gi, '');
214222

215223
if (none) {
216-
return striptags(html);
224+
return striptags(html).replace(/&gt;/gi, '>').replace(/&lt;/gi, '<');
217225
}
218226

219227
if (replaceBold) {
@@ -235,11 +243,15 @@ export const stripHtmlValidation = (
235243
convertMentionFunction
236244
);
237245

238-
return striptags(processedHtml);
246+
return striptags(processedHtml)
247+
.replace(/&gt;/gi, '>')
248+
.replace(/&lt;/gi, '<');
239249
}
240250

241251
// Strip all other tags
242-
return striptags(html, ['ul', 'li', 'h1', 'h2', 'h3']);
252+
return striptags(html, ['ul', 'li', 'h1', 'h2', 'h3'])
253+
.replace(/&gt;/gi, '>')
254+
.replace(/&lt;/gi, '<');
243255
};
244256

245257
export const convertMention = (

0 commit comments

Comments
 (0)