Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fuel-core] Update Content Type regex to better match spec #673

Merged
merged 2 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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