Skip to content
Browse files
Accept image/jpg for compatibility reasons

Reviewed by Said Abou-Hallawa and Darin Adler.

Blink & Gecko seem to render JPEG images served with `Content-Type: image/jpg`
while WebKit decides to download it because the correct content type is
supposed to be `image/jpeg`. This is an interoperability risk so we should

In this patch, we now treat `image/jpg` as a valid JPEG content type to align
with other browser engines.

Also revert a couple of unintended changes that were made in 237163@main:
- The logic in normalizedImageMIMEType() was for CURL only but the condition got
  mistakenly reversed.
- The normalized MIME type was previously used for both supportedImageMIMETypeSet
  and additionalSupportedImageMIMETypes. However, 237163@main stopped using the
  normalized MIME type for supportedImageMIMETypeSet.

* LayoutTests/http/tests/images/jpg-invalid-content-type-expected.html: Added.
* LayoutTests/http/tests/images/jpg-invalid-content-type.html: Added.
* Source/WebCore/platform/MIMETypeRegistry.cpp:

Canonical link:
  • Loading branch information
cdumez committed Oct 7, 2022
1 parent 05f0430 commit 0d17dc0c310f9b1d05268ab63e967c38133892f0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
@@ -0,0 +1,7 @@
<DOCTYPE html>
<p>Tests that a JPEG image served with `Content-Type: image/jpg` gets rendered, and not downloaded.</p>
<iframe id="testFrame" src="/resources/square20.jpg"></iframe>
@@ -0,0 +1,18 @@
<DOCTYPE html>
<p>Tests that a JPEG image served with `Content-Type: image/jpg` gets rendered, and not downloaded.</p>
<iframe id="testFrame" src="about:blank"></iframe>
if (window.testRunner)

let testFrame = document.getElementById("testFrame");
testFrame.src = "/resources/";
testFrame.onload = () => {
if (window.testRunner)
@@ -113,6 +113,7 @@ constexpr ComparableCaseFoldingASCIILiteral supportedImageMIMETypeArray[] = {
@@ -422,9 +423,11 @@ bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
if (supportedImageMIMETypeSet.contains(mimeType))

String normalizedMIMEType = normalizedImageMIMEType(mimeType);
if (supportedImageMIMETypeSet.contains(normalizedMIMEType))
return true;
return additionalSupportedImageMIMETypes().contains(normalizedImageMIMEType(mimeType));
return additionalSupportedImageMIMETypes().contains(normalizedMIMEType);

bool MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(const String& mimeType)
@@ -715,8 +718,6 @@ bool MIMETypeRegistry::isSupportedModelMIMEType(const String& mimeType)
static String normalizedImageMIMEType(const String& mimeType)
return mimeType;
// FIXME: Since this is only used in isSupportedImageMIMEType, we should consider removing the non-image types below.
static constexpr std::pair<ComparableLettersLiteral, ASCIILiteral> mimeTypeAssociationArray[] = {
{ "application/ico", "image/"_s },
@@ -769,6 +770,8 @@ static String normalizedImageMIMEType(const String& mimeType)
static constexpr SortedArrayMap associationMap { mimeTypeAssociationArray };
auto normalizedType = associationMap.tryGet(mimeType);
return normalizedType ? *normalizedType : mimeType;
return mimeType;

@@ -845,7 +848,7 @@ bool MIMETypeRegistry::isJPEGMIMEType(const String& mimeType)
return false;
return CFEqual(destinationUTI.get(), jpegUTI());
return mimeType == "image/jpeg"_s;
return mimeType == "image/jpeg"_s || mimeType == "image/jpg"_s;


if (equalLettersIgnoringASCIICase(mimeType, "image/png"_s))
return kUTTypePNG;
if (equalLettersIgnoringASCIICase(mimeType, "image/jpeg"_s))
if (equalLettersIgnoringASCIICase(mimeType, "image/jpeg"_s) || equalLettersIgnoringASCIICase(mimeType, "image/jpg"_s))
return jpegUTI();
if (equalLettersIgnoringASCIICase(mimeType, "image/gif"_s))
return kUTTypeGIF;

0 comments on commit 0d17dc0

Please sign in to comment.