Skip to content

Commit e467ffa

Browse files
committed
Quicker escape_html_chars function.
1 parent 215fec8 commit e467ffa

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎js/pgm.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/js/pgm.js‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,22 @@ function createSentLookupLink (torder, txid, url, txt) {
10001000
/**
10011001
* Replace html characters with encodings
10021002
*
1003+
* See https://stackoverflow.com/questions/1787322/what-is-the-htmlspecialchars-equivalent-in-javascript
1004+
*
10031005
* @param {string} s String to be escaped
10041006
* @returns {string} Escaped string
10051007
*/
1006-
function escape_html_chars (s) {
1007-
return s
1008-
.replace(/&/g, '%AMP%')
1009-
.replace(/</g, '&#060;').replace(/>/g, '&#062;')
1010-
.replace(/"/g, '&#034;').replace(/'/g, '&#039;')
1011-
.replace(/%AMP%/g, '&#038;')
1012-
.replace(/\x0d/g, '<br />');
1008+
function escape_html_chars(s) {
1009+
let map = {
1010+
'&': '&amp;',
1011+
'<': '&lt;',
1012+
'>': '&gt;',
1013+
'"': '&quot;',
1014+
"'": '&#039;',
1015+
"\x0d": '<br />' // This one inserts HTML, delete? (2.9.0)
1016+
};
1017+
1018+
return s.replace(/[&<>"'\x0d]/g, function(m) { return map[m]; });
10131019
}
10141020

10151021
/**

0 commit comments

Comments
 (0)