Skip to content

Commit

Permalink
Fix image format detection for upper case extensions, e.g. JPG
Browse files Browse the repository at this point in the history
This regression was introduced in 0.56.0.

Fixes #6137
  • Loading branch information
bep committed Jul 30, 2019
1 parent 00a238e commit c62bbf7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions resources/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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} {
Expand Down
2 changes: 1 addition & 1 deletion resources/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added resources/testdata/sunrise.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c62bbf7

Please sign in to comment.