Skip to content

Commit

Permalink
Allow plus sign in mimetype subtype, expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pieter-edelman-nictiz committed Jun 21, 2024
1 parent 7743496 commit 944db4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class MimeTypeUtil {
public static String checkValidMimeType(String mt) {
if (!mt.matches("^(\\w+|\\*)/([\\w-]+|\\*)((;\\s*(\\w+)=\\s*(\\S+))?)$")) {
if (!mt.matches("^(\\w+|\\*)/([\\w-+]+|\\*)((;\\s*(\\w+)=\\s*(\\S+))?)$")) {
return "Mime type invalid";
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ public class MimeTypeUtilTest {
@ValueSource(strings = {
"application/fhir",
"text/plain",
"text/plain;charset=UTF-8",
"application/octet-stream",
//"application/xhtml+xml", // This is technically valid but doesn't currently pass
"application/xhtml+xml",
})
public void testValidMimeTypes(String mimeType) {
testMimeType(mimeType, true);
}

@ParameterizedTest
@ValueSource(strings = {
"application/fhir;anything" // semicolon and everything after shouldn't work.
"application/fhir;anything", // semicolon and everything after shouldn't work if it's not a parameter=value pair
"application/fhir;parameter=", // parameter without value shouldn't work.
})
public void testInvalidMimeTypes(String mimeType) {
testMimeType(mimeType, false);
Expand Down

0 comments on commit 944db4a

Please sign in to comment.