Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

URLEncode cookie values as otherwise the syntax makes the cookie unre…

…adable, preventing enabling multiple features
  • Loading branch information...
commit 02c0cb7ad22483e5dde924e0a579075e89fd838e 1 parent c109a9a
@theefer theefer authored
View
9 src/main/scala/com/gu/featureswitching/CookieFeatureSwitchingOverrideStrategy.scala
@@ -1,6 +1,7 @@
package com.gu.featureswitching
import org.scalatra._
+import java.net.{URLDecoder, URLEncoder}
trait CookieFeatureSwitchingOverrideStrategy extends FeatureSwitchingOverrideStrategy
with ScalatraKernel with CookieSupport {
@@ -9,14 +10,18 @@ trait CookieFeatureSwitchingOverrideStrategy extends FeatureSwitchingOverrideStr
// TODO: clear obsolete keys for non-existing features, by reading the list of existing switches
private def rawValue = cookies.get(featureSwitchOverrideKey).getOrElse("")
+ private def rawCookie = URLDecoder.decode(rawValue, "utf-8")
- private def cookieMap = rawValue.split(",").map(_.split("=").toList).flatMap {
+ private def cookieMap = rawCookie.split(",").map(_.split("=").toList).flatMap {
case List(key, "true") => Some((key -> true))
case List(key, "false") => Some((key -> false))
case _ => None // invalid token, ignore
}.toMap
- private def renderCookie(newCookieMap: Map[String, Boolean]) = newCookieMap.map {
+ private def renderCookie(newCookieMap: Map[String, Boolean]) =
+ URLEncoder.encode(renderCookieString(newCookieMap), "utf-8")
+
+ private def renderCookieString(newCookieMap: Map[String, Boolean]) = newCookieMap.map {
case (key, value) => "%s=%s".format(key, value)
}.toList.mkString(",")
Please sign in to comment.
Something went wrong with that request. Please try again.