Skip to content

Commit

Permalink
chore: remove slow regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuiRuTian committed Dec 7, 2024
1 parent 11f7674 commit e8e2fff
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions packages/shared/src/escapeHtml.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
const escapeRE = /["'&<>]/

export function escapeHtml(string: unknown): string {
const str = '' + string
const match = escapeRE.exec(str)

if (!match) {
return str
}

let html = ''
let escaped: string
let index: number
let lastIndex = 0
for (index = match.index; index < str.length; index++) {
for (index = 0; index < str.length; index++) {
switch (str.charCodeAt(index)) {
case 34: // "
escaped = '&quot;'
Expand Down

0 comments on commit e8e2fff

Please sign in to comment.