Permalink
Browse files

Fix encoding issues in the test by forming the raw HTTP request progr…

…ammatically
  • Loading branch information...
1 parent 947e6e6 commit df4a2994c8fbe6d99750515c951576faab979ef4 @mnylen committed Apr 11, 2012
Showing with 26 additions and 1 deletion.
  1. +26 −1 core/src/test/scala/org/scalatra/servlet/FileUploadSupportSpec.scala
@@ -8,6 +8,7 @@ import org.eclipse.jetty.testing.HttpTester
import org.eclipse.jetty.servlet.ServletHolder
import javax.servlet.MultipartConfigElement
import org.specs2.execute.Pending
+import org.scalatra.test.MultipartHttpTester
class FileUploadSupportSpecServlet extends ScalatraServlet with FileUploadSupport {
def headersToHeaders() {
@@ -154,6 +155,30 @@ class FileUploadSupportSpec extends MutableScalatraSpec {
res
}
+ def multipartResponseWithEncodingFixture(path: String) = {
+ val req = new MultipartHttpTester()
+ req.setURI(path)
+ req.setMethod("POST")
+ req.setVersion("HTTP/1.0")
+ req.setHeader("Content-Type", "multipart/form-data; boundary=XyXyXyXyXyXy")
+
+ val content = (
+ "--XyXyXyXyXyXy\r\n" +
+ "Content-Disposition: form-data; name=\"latin1-string\"\r\n" +
+ "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
+ "\r\n" +
+ "äöööölfldflfldfdföödfödfödfåååååå\r\n" +
+ "--XyXyXyXyXyXy--"
+ ).getBytes("ISO-8859-1")
+
+ req.setContent(content)
+
+ val res = new HttpTester("iso-8859-1")
+ res.parse(tester.getResponses(req.generateBytes()).array())
+
+ res
+ }
+
"POST with multipart/form-data" should {
"route correctly to action" in {
postExample {
@@ -239,7 +264,7 @@ class FileUploadSupportSpec extends MutableScalatraSpec {
}
"use the charset specified in Content-Type header of a part for decoding form params" in {
- val res = multipartResponse("/params", "multipart_request_charset_handling.txt")
+ val res = multipartResponseWithEncodingFixture("/params")
res.header("latin1-string") must_== "äöööölfldflfldfdföödfödfödfåååååå"
}
}

0 comments on commit df4a299

Please sign in to comment.