Skip to content

Instantly share code, notes, and snippets.

@windymelt
Created December 10, 2013 16:45
Show Gist options
  • Save windymelt/7893820 to your computer and use it in GitHub Desktop.
Save windymelt/7893820 to your computer and use it in GitHub Desktop.
Play-2.2.1をSJISに対応させるパッチ(仮)
diff -ru play-2.2.1 2/framework/project/plugins.sbt play-2.2.1/framework/project/plugins.sbt
--- play-2.2.1 2/framework/project/plugins.sbt 2013-10-30 16:44:48.000000000 +0900
+++ play-2.2.1/framework/project/plugins.sbt 2013-11-08 02:13:56.000000000 +0900
@@ -6,6 +6,8 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.6.0")
+addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0")
+
libraryDependencies <+= sbtVersion { sv =>
"org.scala-sbt" % "scripted-plugin" % sv
}
diff -ru play-2.2.1 2/framework/src/play/src/main/scala/play/api/mvc/Binders.scala play-2.2.1/framework/src/play/src/main/scala/play/api/mvc/Binders.scala
--- play-2.2.1 2/framework/src/play/src/main/scala/play/api/mvc/Binders.scala 2013-10-30 16:44:48.000000000 +0900
+++ play-2.2.1/framework/src/play/src/main/scala/play/api/mvc/Binders.scala 2013-11-08 03:41:42.000000000 +0900
@@ -268,7 +268,7 @@
*/
implicit def bindableString = new QueryStringBindable[String] {
def bind(key: String, params: Map[String, Seq[String]]) = params.get(key).flatMap(_.headOption).map(Right(_)) // No need to URL decode from query string since netty already does that
- def unbind(key: String, value: String) = key + "=" + (URLEncoder.encode(value, "utf-8"))
+ def unbind(key: String, value: String) = key + "=" + (URLEncoder.encode(value, "Shift_JIS"))
}
/**
diff -ru play-2.2.1 2/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala play-2.2.1/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala
--- play-2.2.1 2/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala 2013-10-30 16:44:48.000000000 +0900
+++ play-2.2.1/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala 2013-11-08 19:15:46.000000000 +0900
@@ -300,7 +300,7 @@
import Execution.Implicits.trampoline
Traversable.takeUpTo[Array[Byte]](maxLength)
- .transform(Iteratee.consume[Array[Byte]]().map(c => new String(c, request.charset.getOrElse("ISO-8859-1"))))
+ .transform(Iteratee.consume[Array[Byte]]().map(c => new String(c, request.charset.getOrElse("SJIS"))))
.flatMap(Iteratee.eofOrElse(Results.EntityTooLarge))
}
@@ -414,7 +414,7 @@
// XML, and therefore nothing about RFC 3023, but rather conforms to RFC 2616, will send ISO-8859-1.
// Since decoding as ISO-8859-1 works for both clients that conform to RFC 3023, and clients that conform
// to RFC 2616, we use that.
- case mt if mt.mediaType == "text" => "iso-8859-1"
+ case mt if mt.mediaType == "text" => "SJIS"
// Otherwise, there should be no default, it will be detected by the XML parser.
}
).foreach { charset =>
@@ -485,7 +485,7 @@
def tolerantFormUrlEncoded(maxLength: Int): BodyParser[Map[String, Seq[String]]] =
tolerantBodyParser("urlFormEncoded", maxLength, "Error parsing application/x-www-form-urlencoded") { (request, bytes) =>
import play.core.parsers._
- FormUrlEncodedParser.parse(new String(bytes, request.charset.getOrElse("utf-8")), request.charset.getOrElse("utf-8"))
+ FormUrlEncodedParser.parse(new String(bytes, request.charset.getOrElse("SJIS")), request.charset.getOrElse("SJIS"))
}
/**
@@ -588,7 +588,7 @@
mt <- request.mediaType
(_, value) <- mt.parameters.find(_._1.equalsIgnoreCase("boundary"))
boundary <- value
- } yield ("\r\n--" + boundary).getBytes("utf-8")
+ } yield ("\r\n--" + boundary).getBytes("SJIS")
maybeBoundary.map { boundary =>
@@ -606,7 +606,7 @@
val collectHeaders = maxHeaderBuffer.map { buffer =>
val (headerBytes, rest) = Option(buffer.drop(2)).map(b => b.splitAt(b.indexOfSlice(CRLFCRLF))).get
- val headerString = new String(headerBytes, "utf-8")
+ val headerString = new String(headerBytes, "Shift_JIS")
val headers = headerString.lines.map { header =>
val key :: value = header.trim.split(":").toList
(key.trim.toLowerCase, value.mkString.trim)
@@ -755,7 +755,7 @@
case headers @ PartInfoMatcher(partName) if !FileInfoMatcher.unapply(headers).isDefined =>
import play.api.libs.iteratee.Execution.Implicits.trampoline
Traversable.takeUpTo[Array[Byte]](DEFAULT_MAX_TEXT_LENGTH)
- .transform(Iteratee.consume[Array[Byte]]().map(bytes => DataPart(partName, new String(bytes, "utf-8"))))
+ .transform(Iteratee.consume[Array[Byte]]().map(bytes => DataPart(partName, new String(bytes, "SJIS"))))
.flatMap { data =>
Cont({
case Input.El(_) => Done(MaxDataPartSizeExceeded(partName), Input.Empty)
diff -ru play-2.2.1 2/framework/src/play/src/main/scala/play/core/parsers/FormUrlEncodedParser.scala play-2.2.1/framework/src/play/src/main/scala/play/core/parsers/FormUrlEncodedParser.scala
--- play-2.2.1 2/framework/src/play/src/main/scala/play/core/parsers/FormUrlEncodedParser.scala 2013-10-30 16:44:48.000000000 +0900
+++ play-2.2.1/framework/src/play/src/main/scala/play/core/parsers/FormUrlEncodedParser.scala 2013-12-11 01:26:59.000000000 +0900
@@ -5,9 +5,9 @@
*/
object FormUrlEncodedParser {
- def parse(data: String, encoding: String = "utf-8"): Map[String, Seq[String]] = {
+ def parse(data: String, encoding: String = "SJIS"): Map[String, Seq[String]] = {
- import java.net._
+ import org.apache.commons.codec.net.URLCodec
import scala.collection.mutable.{ HashMap }
var params = HashMap.empty[String, Seq[String]]
@@ -17,8 +17,8 @@
if (param.contains('=')) {
val parts = param.split('=')
- val key = URLDecoder.decode(parts.head, encoding)
- val value = URLDecoder.decode(parts.tail.headOption.getOrElse(""), encoding)
+ val key = new URLCodec(encoding).decode(parts.head, encoding)
+ val value = new URLCodec(encoding).decode(parts.tail.headOption.getOrElse(""), encoding)
params += key -> (params.get(key).getOrElse(Seq.empty) :+ value)
@@ -28,4 +28,4 @@
params.toMap
}
-}
\ No newline at end of file
+}
diff -ru play-2.2.1 2/framework/src/sbt-plugin/src/main/scala/play/Project.scala play-2.2.1/framework/src/sbt-plugin/src/main/scala/play/Project.scala
--- play-2.2.1 2/framework/src/sbt-plugin/src/main/scala/play/Project.scala 2013-10-30 16:44:48.000000000 +0900
+++ play-2.2.1/framework/src/sbt-plugin/src/main/scala/play/Project.scala 2013-11-08 18:08:03.000000000 +0900
@@ -36,8 +36,8 @@
intellijCommandSettings ++
Seq(testListeners += testListener) ++
Seq(
- scalacOptions ++= Seq("-deprecation", "-unchecked", "-encoding", "utf8"),
- javacOptions in Compile ++= Seq("-encoding", "utf8", "-g")
+ scalacOptions ++= Seq("-deprecation", "-unchecked", "-encoding", "Shift_JIS"),
+ javacOptions in Compile ++= Seq("-encoding", "Shift_JIS", "-g")
)
lazy val playJavaSettings: Seq[Setting[_]] =
@@ -66,4 +66,4 @@
.settings(projectSettings: _*)
.settings(settings: _*)
}
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment