Skip to content

Instantly share code, notes, and snippets.

@dkumar431
Created October 28, 2016 09:31
Show Gist options
  • Save dkumar431/5e01ecd1cebfb8ddcc65a6ce883fb6eb to your computer and use it in GitHub Desktop.
Save dkumar431/5e01ecd1cebfb8ddcc65a6ce883fb6eb to your computer and use it in GitHub Desktop.
<%#= '<script>alert("Hii")</script>' %>
<!--The above will escape by default-->
<%#= '<script>alert("Hii")</script>'.html_safe %>
<!--The above will alert Hii because we are marking the string as safe.-->
<%#= h('<script>alert("Hii")</script>') %>
<!--Its same as the first one.-->
<%#= raw('<script>alert("Hii")</script>') %>
<!--The above will alert Hii because raw = "".to_s.html_safe-->
<%= sanitize '<script>alert("Hii")</script>' %>
<!--removes the script tag and prints alert("Hii") -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment