Skip to content
Permalink
Browse files

Bug fix to ContentType parsing

  • Loading branch information
darkfrog26 committed Nov 22, 2019
1 parent 5845f19 commit 19855d2d004dc7392d40e32ba4a9e7a2b31a31cf
@@ -4,7 +4,7 @@ import sbtcrossproject.CrossType

name := "youi"
organization in ThisBuild := "io.youi"
version in ThisBuild := "0.12.8"
version in ThisBuild := "0.12.9-SNAPSHOT"
scalaVersion in ThisBuild := "2.13.1"
crossScalaVersions in ThisBuild := List("2.13.1", "2.12.10")
resolvers in ThisBuild ++= Seq(
@@ -1810,13 +1810,15 @@ object ContentType {
var contentType = ContentType(`type`, subType)
parts.tail.foreach { s =>
val block = s.trim
val divider = block.indexOf('=')
if (divider == -1) {
throw new RuntimeException(s"Unable to parse content type: [$contentTypeString]")
if (block.nonEmpty) {
val divider = block.indexOf('=')
if (divider == -1) {
throw new RuntimeException(s"Unable to parse content type: [$contentTypeString], block: [$block]")
}
val name = block.substring(0, divider)
val value = block.substring(divider + 1)
contentType = contentType.withExtra(name, value)
}
val name = block.substring(0, divider)
val value = block.substring(divider + 1)
contentType = contentType.withExtra(name, value)
}
contentType
}
@@ -13,5 +13,12 @@ class ContentTypeSpec extends AnyWordSpec with Matchers {
ct.subType should be("related")
ct.outputString should be("""multipart/related; start="<rootpart*1faa50c8-1aec-4659-ba8b-372a789b1945@example.jaxws.sun.com>"; type="application/xop+xml"; boundary="uuid:1faa50c8-1aec-4659-ba8b-372a789b1945"; start-info="text/xml"""")
}
"parse a simple type with dual semi-colons" in {
val s = "text/html;;charset=UTF-8"
val ct = ContentType.parse(s)
ct.`type` should be("text")
ct.subType should be("html")
ct.charSet should be("UTF-8")
}
}
}

0 comments on commit 19855d2

Please sign in to comment.
You can’t perform that action at this time.