Created
December 23, 2012 05:53
-
-
Save tan-yuki/4362208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sanitizing string value. | |
* | |
* @require jQuery | |
*/ | |
(function($) { | |
var $div = $('<div/>'); | |
String.prototype.sanitize = function() { | |
return $div.text(this)[0].innerHTML; | |
}; | |
}) (jQuery); | |
/* | |
* var html = '<script>alert("hello");</script>'; | |
* html.sanitize(); // === "<script>alert("hello");</script>" | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment