Fix image format detection for upper case extensions, e.g. JPG
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 30 Jul 2019 06:53:50 +0000 (08:53 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 30 Jul 2019 06:53:50 +0000 (08:53 +0200)
This regression was introduced in 0.56.0.

Fixes #6137

resources/image_test.go
resources/resource.go
resources/testdata/sunrise.JPG [new file with mode: 0644]

index 6639dbb2448cfb71bd8fa97cdcc9e156c5126eec..061ae771027ec53d3c45d3504d73ba8025894b52 100644 (file)
@@ -152,6 +152,16 @@ func TestImageTransformLongFilename(t *testing.T) {
        assert.Equal("/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_c876768085288f41211f768147ba2647.jpg", resized.RelPermalink())
 }
 
+// Issue 6137
+func TestImageTransformUppercaseExt(t *testing.T) {
+       assert := require.New(t)
+       image := fetchImage(assert, "sunrise.JPG")
+       resized, err := image.Resize("200x")
+       assert.NoError(err)
+       assert.NotNil(resized)
+       assert.Equal(200, resized.Width())
+}
+
 // https://github.com/gohugoio/hugo/issues/5730
 func TestImagePermalinkPublishOrder(t *testing.T) {
        for _, checkOriginalFirst := range []bool{true, false} {
index 236ba8ac6b37022bef603ed8d32d75476aaeb7b5..0aee4a052451c46fa8f1e65cb5aec13fce08681f 100644 (file)
@@ -209,7 +209,7 @@ func (r *Spec) newResource(sourceFs afero.Fs, fd ResourceSourceDescriptor) (reso
                fd.RelTargetFilename = sourceFilename
        }
 
-       ext := filepath.Ext(fd.RelTargetFilename)
+       ext := strings.ToLower(filepath.Ext(fd.RelTargetFilename))
        mimeType, found := r.MediaTypes.GetFirstBySuffix(strings.TrimPrefix(ext, "."))
        // TODO(bep) we need to handle these ambigous types better, but in this context
        // we most likely want the application/xml type.
diff --git a/resources/testdata/sunrise.JPG b/resources/testdata/sunrise.JPG
new file mode 100644 (file)
index 0000000..7d7307b
Binary files /dev/null and b/resources/testdata/sunrise.JPG differ