Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit ad5b8e7

Browse files
committed
Bad media type: *; q=.2 fix jooby-project#197
1 parent b6c1192 commit ad5b8e7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

jooby/src/main/java/org/jooby/MediaType.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ public static MediaType valueOf(final String type) {
499499
return aliastype;
500500
}
501501
String[] parts = type.trim().split(";");
502+
if (parts[0].equals("*")) {
503+
// odd and ugly media type
504+
return MediaType.all;
505+
}
502506
String[] typeAndSubtype = parts[0].split("/");
503507
checkArgument(typeAndSubtype.length == 2, "Bad media type: %s", type);
504508
String stype = typeAndSubtype[0].trim();
@@ -616,4 +620,4 @@ public static Optional<MediaType> byExtension(final String ext) {
616620
return Optional.empty();
617621
}
618622

619-
}
623+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.jooby.issues;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.jooby.MediaType;
6+
import org.junit.Test;
7+
8+
public class Issue197 {
9+
10+
@Test
11+
public void shouldParseOddMediaType() {
12+
MediaType type = MediaType.parse("*; q=.2").iterator().next();
13+
assertEquals("*/*", type.name());
14+
}
15+
}

0 commit comments

Comments
 (0)