aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStewart Stewart <stewinsalot@gmail.com>2017-03-21 21:22:18 -0400
committerStewart Stewart <stewinsalot@gmail.com>2017-03-21 21:24:24 -0400
commit61fe057cd3651773b1ac353d33ea60d6626d4ec3 (patch)
tree0bc472753762d17671b7cccbb947b9718241e4cf
parente253b5d428e9b87209575a0e790e715aae20453a (diff)
downloaddriver-core-61fe057cd3651773b1ac353d33ea60d6626d4ec3.tar.gz
driver-core-61fe057cd3651773b1ac353d33ea60d6626d4ec3.tar.bz2
driver-core-61fe057cd3651773b1ac353d33ea60d6626d4ec3.zip
slight refactor of escapeScriptTags
-rw-r--r--src/main/scala/xyz/driver/core/rest.scala28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/main/scala/xyz/driver/core/rest.scala b/src/main/scala/xyz/driver/core/rest.scala
index 498ba33..fd86b33 100644
--- a/src/main/scala/xyz/driver/core/rest.scala
+++ b/src/main/scala/xyz/driver/core/rest.scala
@@ -70,19 +70,21 @@ package rest {
}
}
- val firstSlash = byteString.indexOf('/')
- if (firstSlash === -1) byteString
- else {
- val indices = dirtyIndices(firstSlash, Nil) :+ byteString.length
- val builder = ByteString.newBuilder
- builder ++= byteString.take(firstSlash)
- indices.sliding(2).foreach {
- case Seq(start, end) =>
- builder += ' '
- builder ++= byteString.slice(start, end)
- }
- builder.result
- }
+ val indices = dirtyIndices(0, Nil)
+
+ indices.headOption.fold(byteString){head =>
+ val builder = ByteString.newBuilder
+ builder ++= byteString.take(head)
+
+ (indices :+ byteString.length).sliding(2).foreach {
+ case Seq(start, end) =>
+ builder += ' '
+ builder ++= byteString.slice(start, end)
+ case Seq(byteStringLength) => // Should not match; sliding on at least 2 elements
+ assert(indices.nonEmpty, s"Indices should have been nonEmpty: $indices")
+ }
+ builder.result
+ }
}
val sanitizeRequestEntity: Directive0 = {