Skip to content

Commit 63373a4

Browse files
committed
add it all (i can clean it up before merge)
1 parent f1f45c3 commit 63373a4

File tree

3 files changed

+11754
-5
lines changed

3 files changed

+11754
-5
lines changed

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ module.exports = { escapeHtml, escapeHtmlFast, escapeHtmlNoRegex }
3131
*/
3232

3333
var matchHtmlRegExpFast = /["'&<>]/g
34-
function escapeHtmlFast (str) {
34+
function escapeHtmlFast (string) {
35+
var str = '' + string
36+
3537
var lastIndex = 0
3638
var html = ''
3739
var escape = ''
3840
var match
3941

4042
while (match = matchHtmlRegExpFast.test(str)) {
41-
switch (str.charCodeAt(matchHtmlRegExpFast.lastIndex)) {
43+
switch (str.charCodeAt(matchHtmlRegExpFast.lastIndex-1)) {
4244
case 34: // "
4345
escape = '&quot;'
4446
break
@@ -56,8 +58,8 @@ function escapeHtmlFast (str) {
5658
break
5759
}
5860
// console.log(lastIndex, matchHtmlRegExpFast.lastIndex, str.length)
59-
html += str.substring(lastIndex, matchHtmlRegExpFast.lastIndex)
60-
lastIndex = matchHtmlRegExpFast.lastIndex + 1
61+
html += str.substring(lastIndex, matchHtmlRegExpFast.lastIndex - 1)
62+
lastIndex = matchHtmlRegExpFast.lastIndex
6163
html += escape
6264
}
6365
return html + str.substring(lastIndex)

0 commit comments

Comments
 (0)