mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
(refs #251)Remove BOM from UTF-8 string.
This commit is contained in:
@@ -3,6 +3,8 @@ package util
|
||||
import java.net.{URLDecoder, URLEncoder}
|
||||
import org.mozilla.universalchardet.UniversalDetector
|
||||
import util.ControlUtil._
|
||||
import org.apache.commons.io.input.BOMInputStream
|
||||
import org.apache.commons.io.IOUtils
|
||||
|
||||
object StringUtil {
|
||||
|
||||
@@ -27,7 +29,12 @@ object StringUtil {
|
||||
def escapeHtml(value: String): String =
|
||||
value.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """)
|
||||
|
||||
def convertFromByteArray(content: Array[Byte]): String = new String(content, detectEncoding(content))
|
||||
/**
|
||||
* Make string from byte array. Character encoding is detected automatically by [[util.StringUtil.detectEncoding]].
|
||||
* And if given bytes contains UTF-8 BOM, it's removed from returned string..
|
||||
*/
|
||||
def convertFromByteArray(content: Array[Byte]): String =
|
||||
IOUtils.toString(new BOMInputStream(new java.io.ByteArrayInputStream(content)), detectEncoding(content))
|
||||
|
||||
def detectEncoding(content: Array[Byte]): String =
|
||||
defining(new UniversalDetector(null)){ detector =>
|
||||
|
||||
Reference in New Issue
Block a user