Skip to content

Commit

Permalink
[fuel-core] Update Content Type regex to better match spec (#673)
Browse files Browse the repository at this point in the history
* change regex to allow optional whitespace before parameter

* update tests, fixed some extra indent for a few tests
  • Loading branch information
Kenny Tsui authored and SleeplessByte committed Aug 11, 2019
1 parent 3786703 commit 76b08a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.kittinunf.fuel.core
import java.nio.charset.Charset

private val TEXT_CONTENT_TYPE = Regex(
"^(?:text/.*|application/(?:csv|javascript|json|typescript|xml|x-yaml|x-www-form-urlencoded|vnd\\.coffeescript)|.*\\+(?:xml|json))(; charset=.+)*$"
"^(?:text/.*|application/(?:csv|javascript|json|typescript|xml|x-yaml|x-www-form-urlencoded|vnd\\.coffeescript)|.*\\+(?:xml|json))(;(?: |)charset=.+)*$"
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class BodyRepresentationTest : MockHttpTestCase() {

contentTypes.forEach { contentType ->
assertThat(
DefaultBody
.from({ ByteArrayInputStream(content) }, { content.size.toLong() })
.asString(contentType),
equalTo("(555 bytes of $contentType)")
DefaultBody
.from({ ByteArrayInputStream(content) }, { content.size.toLong() })
.asString(contentType),
equalTo("(555 bytes of $contentType)")
)
}
}
Expand Down Expand Up @@ -153,15 +153,15 @@ class BodyRepresentationTest : MockHttpTestCase() {

@Test
fun textRepresentationOfJsonWithUtf8Charset() {
val contentTypes = listOf("application/json; charset=utf-8")
val contentTypes = listOf("application/json;charset=utf-8", "application/json; charset=utf-8")
val content = "{ \"foo\": 42 }"

contentTypes.forEach { contentType ->
assertThat(
DefaultBody
.from({ ByteArrayInputStream(content.toByteArray()) }, { content.length.toLong() })
.asString(contentType),
equalTo(content)
DefaultBody
.from({ ByteArrayInputStream(content.toByteArray()) }, { content.length.toLong() })
.asString(contentType),
equalTo(content)
)
}
}
Expand All @@ -183,15 +183,15 @@ class BodyRepresentationTest : MockHttpTestCase() {

@Test
fun textRepresentationOfCsvWithUtf16beCharset() {
val contentTypes = listOf("application/csv; charset=utf-16be")
val contentTypes = listOf("application/csv; charset=utf-16be", "application/csv;charset=utf-16be")
val content = String("hello,world!".toByteArray(Charsets.UTF_16BE))

contentTypes.forEach { contentType ->
assertThat(
DefaultBody
.from({ ByteArrayInputStream(content.toByteArray()) }, { content.length.toLong() })
.asString(contentType),
equalTo("hello,world!")
DefaultBody
.from({ ByteArrayInputStream(content.toByteArray()) }, { content.length.toLong() })
.asString(contentType),
equalTo("hello,world!")
)
}
}
Expand Down

0 comments on commit 76b08a4

Please sign in to comment.