mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Improve escapeHTML
Replacing one char after another is not a best practice, due to the order dependency of replacing, xss risk and performance. Fix #1577
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
function escapeHTML(str) {
|
||||
return str.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'")
|
||||
.replace(/\//g,"/");
|
||||
var escaped = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
"/": "/"
|
||||
};
|
||||
|
||||
return str.replace(/[&<>'"\/]/g, function(m) {
|
||||
return escaped[m];
|
||||
});
|
||||
}
|
||||
|
||||
function randomId() {
|
||||
|
||||
Reference in New Issue
Block a user