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

fix: content-type super-type resolution for application/octet-stream … #1137

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 @@ -48,7 +48,7 @@ class ContentType(val contentType: MediaType?) {

fun isBinaryType(): Boolean {
return if (contentType != null) {
val superType = registry.getSupertype(contentType)
val superType = registry.getSupertype(contentType) ?: MediaType.OCTET_STREAM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** * Returns the supertype of the given type. If the media type database * has an explicit inheritance rule for the type, then that is used. * Next, if the given type has any parameters, then the respective base * type (parameter-less) is returned. Otherwise built-in heuristics like * text/... -&gt; text/plain and .../...+xml -&gt; application/xml are used. * Finally application/octet-stream is returned for all types for which no other * supertype is known, and the return value for application/octet-stream * is <code>null</code>. * * @since Apache Tika 0.8 * @param type media type * @return supertype, or <code>null</code> for application/octet-stream */ public MediaType getSupertype(MediaType type) {

val type = contentType.type
val baseType = superType.type
val override = System.getProperty("pact.content_type.override.$type.${contentType.subtype}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,22 @@ class ContentTypeSpec extends Specification {

where:

value || result
'' || false
'text/plain' || false
'application/pdf' || true
'application/zip' || true
'application/json' || false
'application/hal+json' || false
'application/HAL+JSON' || false
'application/xml' || false
'application/atom+xml' || false
'image/jpeg' || true
'video/H264' || true
'audio/aac' || true
'text/csv' || false
'multipart/form-data' || true
value || result
'' || false
'text/plain' || false
'application/pdf' || true
'application/zip' || true
'application/json' || false
'application/hal+json' || false
'application/HAL+JSON' || false
'application/xml' || false
'application/atom+xml' || false
'application/octet-stream' || true
'image/jpeg' || true
'video/H264' || true
'audio/aac' || true
'text/csv' || false
'multipart/form-data' || true

contentType = new ContentType(value)
}
Expand Down