mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Fix url encoding to encode whitespace to %20
This commit is contained in:
@@ -20,7 +20,7 @@ object StringUtil {
|
||||
md.digest.map(b => "%02x".format(b)).mkString
|
||||
}
|
||||
|
||||
def urlEncode(value: String): String = URLEncoder.encode(value, "UTF-8")
|
||||
def urlEncode(value: String): String = URLEncoder.encode(value, "UTF-8").replace("+", "%20")
|
||||
|
||||
def urlDecode(value: String): String = URLDecoder.decode(value, "UTF-8")
|
||||
|
||||
|
||||
@@ -4,11 +4,21 @@ import org.specs2.mutable._
|
||||
|
||||
class StringUtilSpec extends Specification {
|
||||
|
||||
"urlEncode" should {
|
||||
"encode whitespace to %20" in {
|
||||
val encoded = StringUtil.urlEncode("aa bb")
|
||||
encoded mustEqual "aa%20bb"
|
||||
}
|
||||
}
|
||||
|
||||
"urlDecode" should {
|
||||
"decode encoded string to original string" in {
|
||||
val encoded = StringUtil.urlEncode("あいうえお")
|
||||
StringUtil.urlDecode(encoded) mustEqual "あいうえお"
|
||||
}
|
||||
"decode en%20 to whitespace" in {
|
||||
StringUtil.urlDecode("aa%20bb") mustEqual "aa bb"
|
||||
}
|
||||
}
|
||||
|
||||
"splitWords" should {
|
||||
|
||||
Reference in New Issue
Block a user