1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

fixed double escape html

This commit is contained in:
Nguyễn Việt Hưng
2018-05-20 19:24:36 +07:00
parent 9893fd9ae5
commit 1516807ed5

View File

@@ -15,43 +15,12 @@ export function escapeHtmlCharacters (text) {
return str return str
} }
let escape return str
let html = '' .replace(/&/g, '&')
let index = 0 .replace(/</g, '&lt;')
let lastIndex = 0 .replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
for (index = match.index; index < str.length; index++) { .replace(/'/g, '&#039;')
switch (str.charCodeAt(index)) {
case 34: // "
escape = '&quot;'
break
case 38: // &
escape = '&amp;'
break
case 39: // '
escape = '&#39;'
break
case 60: // <
escape = '&lt;'
break
case 62: // >
escape = '&gt;'
break
default:
continue
}
if (lastIndex !== index) {
html += str.substring(lastIndex, index)
}
lastIndex = index + 1
html += escape
}
return lastIndex !== index
? html + str.substring(lastIndex, index)
: html
} }
export default { export default {