Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About escapeHTML in util.js #1577

Closed
albertosantini opened this issue Feb 10, 2017 · 1 comment
Closed

About escapeHTML in util.js #1577

albertosantini opened this issue Feb 10, 2017 · 1 comment

Comments

@albertosantini
Copy link
Contributor

albertosantini commented Feb 10, 2017

https://github.com/rstudio/shiny/blob/master/srcjs/utils.js#L1

After reading about replacing one char after another is not a best practice (due to the order dependency of replacing and xss risk), I would suggest something like

function escape(s) {
  var escaped = {
    '&': '&',
    '<': '&lt;',
    '>': '&gt;',
    "'": '&#39;',
    '"': '&quot;'
  };
  return s.replace(/[&<>'"]/g, function (m) {
    return escaped[m];
  });
}

Credits to https://gist.github.com/WebReflection/df05641bd04954f6d366.

If you think there is some point here, I may prepare a PR.

@wch
Copy link
Collaborator

wch commented Feb 10, 2017

Sure, that sounds like a good idea. According to this, that method is also faster than what we currently have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants