mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00:00
resource: Fix path duplication/flattening in processed images
Fixes #4502 Closes #4501
This commit is contained in:
@@ -16,6 +16,7 @@ package resource
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
@@ -278,6 +279,39 @@ func TestImageResize8BitPNG(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestImageResizeInSubPath(t *testing.T) {
|
||||
|
||||
assert := require.New(t)
|
||||
|
||||
image := fetchImage(assert, "sub/gohugoio2.png")
|
||||
|
||||
assert.Equal(imaging.PNG, image.format)
|
||||
assert.Equal("/a/sub/gohugoio2.png", image.RelPermalink())
|
||||
assert.Equal("image", image.ResourceType())
|
||||
|
||||
resized, err := image.Resize("101x101")
|
||||
assert.NoError(err)
|
||||
assert.Equal(imaging.PNG, resized.format)
|
||||
assert.Equal("/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png", resized.RelPermalink())
|
||||
assert.Equal(101, resized.Width())
|
||||
|
||||
assertFileCache(assert, image.spec.Fs, resized.RelPermalink(), 101, 101)
|
||||
publishedImageFilename := filepath.Join("/public", resized.RelPermalink())
|
||||
assertImageFile(assert, image.spec.Fs, publishedImageFilename, 101, 101)
|
||||
assert.NoError(image.spec.Fs.Destination.Remove(publishedImageFilename))
|
||||
|
||||
// Cleare mem cache to simulate reading from the file cache.
|
||||
resized.spec.imageCache.clear()
|
||||
|
||||
resizedAgain, err := image.Resize("101x101")
|
||||
assert.NoError(err)
|
||||
assert.Equal("/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png", resizedAgain.RelPermalink())
|
||||
assert.Equal(101, resizedAgain.Width())
|
||||
assertFileCache(assert, image.spec.Fs, resizedAgain.RelPermalink(), 101, 101)
|
||||
assertImageFile(assert, image.spec.Fs, publishedImageFilename, 101, 101)
|
||||
|
||||
}
|
||||
|
||||
func TestSVGImage(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
spec := newTestResourceSpec(assert)
|
||||
|
Reference in New Issue
Block a user