=htp reduce set of not-encoded characters in FormData marshalling

Port of https://github.com/spray/spray/pull/918
This commit is contained in:
Mathias 2014-10-06 10:40:24 +02:00
parent 27c5167e73
commit 46d51e531f
3 changed files with 48 additions and 3 deletions

View file

@ -0,0 +1,42 @@
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.http
import scala.concurrent.duration._
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpec }
import org.scalatest.concurrent.ScalaFutures
import akka.actor.ActorSystem
import akka.stream.FlowMaterializer
import akka.http.unmarshalling.Unmarshal
import akka.http.marshalling.Marshal
import akka.http.model._
class FormDataSpec extends WordSpec with Matchers with ScalaFutures with BeforeAndAfterAll {
implicit val system = ActorSystem(getClass.getSimpleName)
implicit val materializer = FlowMaterializer()
import system.dispatcher
val formData = FormData(Map("surname" -> "Smith", "age" -> "42"))
"The FormData infrastructure" should {
"properly round-trip the fields of www-urlencoded forms" in {
Marshal(formData).to[HttpEntity]
.flatMap(Unmarshal(_).to[FormData]).futureValue shouldEqual formData
}
"properly marshal www-urlencoded forms containing special chars" in {
Marshal(FormData(Map("name" -> "Smith&Wesson"))).to[HttpEntity]
.flatMap(Unmarshal(_).to[String]).futureValue shouldEqual "name=Smith%26Wesson"
Marshal(FormData(Map("name" -> "Smith+Wesson; hopefully!"))).to[HttpEntity]
.flatMap(Unmarshal(_).to[String]).futureValue shouldEqual "name=Smith%2BWesson%3B+hopefully%21"
}
}
override def afterAll() = {
system.shutdown()
system.awaitTermination(10.seconds)
}
}