esamattis / esamattis/underscore.string
Unhandled case in unescapeHTML
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
I got unexpected results when unescaping this string
'"!@#$%^&*()_+{}|":?><~T"est"'
Using the original code, I saw that match and p1 was not correct.
'"@#$%^&_()_+{}|":?><~Test"'.replace(/&([^;]+);/g,function(match,p1,p2,p3){console.log(match + '-' + p1 + '-' + p2 + '-' + p3); return 'boo';})
ORIGINAL RESULT:
&_()_+{}|"-*()_+{}|"-6-"@#$%^&*()_+{}|":?><~Test"
""@#$%^boo:?><~Test""
I expected only to get " for match.
After I looked at the code, I realized the regex was wrong.
Here is the CORRECT REGEX
/&(\w+[^;]|#\d+[^;]);/g
I tested that is still handled > correctly
'"!>@#$%^&_()_+{}|":?><~T"est"'.replace(/&(\w+[^;]|#\d+[^;]);/g,function(match,p1,p2,p3){console.log(match + '-' + p1 + '-' + p2 + '-' + p3); return 'boo';})
>-gt-2-"!>@#$%^&_()_+{}|":?><~T"est"
"-#34-20-"!>@#$%^&*()_+{}|":?><~T"est"
"-quot-31-"!>@#$%^&*()_+{}|":?><~T"est"
Contributor guide
Assessment
This issue has not been assessed yet.