java.lang.Object
com.renomad.minum.utils.StringUtils
Some helper methods for Strings.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteArrayToString(byte[] byteArray) Converts an array of bytes to a string.static StringbyteListToString(List<Byte> byteList) Converts a list of bytes to a string.static StringDecodes URL-encoded UTF-8 text, except that we first check if the string value is the token %NULL%, which is our way to signify null.static StringEncodes UTF-8 text using URL-encodingstatic StringgenerateSecureRandomString(int length) static StringReplace dangerous text that would go inside an HTML attribute.static StringReturns text that has three symbols replaced - the less-than, greater-than, and ampersand.
-
Method Details
-
safeHtml
Returns text that has three symbols replaced - the less-than, greater-than, and ampersand. See ...
If the text is going inside an attribute (e.g.This will protect against something like <div>$USERNAME</div> allowing a username of <script>alert(1)</script> becoming <div><script>alert(1)</script</div> and instead becomes <div><script>alert(1)</script></div><div class="TEXT_GOES_HERE">) Then you need to escape slightly differently. In that case see [safeAttr] -
safeAttr
Replace dangerous text that would go inside an HTML attribute. SeesafeHtml(String)
If we get a null string, just return an empty string
example: Given alert('XSS Attack') Get alert('XSS Attack') -
encode
Encodes UTF-8 text using URL-encoding -
decode
Decodes URL-encoded UTF-8 text, except that we first check if the string value is the token %NULL%, which is our way to signify null. -
generateSecureRandomString
-
byteListToString
Converts a list of bytes to a string. Returns null if the input is null. -
byteArrayToString
Converts an array of bytes to a string. Returns null if the input is null.
-