Skip to content

Commit e141294

Browse files
committed
resource: Avoid potential case issue in image names
1 parent 612dcc1 commit e141294

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

resource/image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func (i *Image) setBasePath(conf imageConfig) {
503503

504504
func (i *Image) filenameFromConfig(conf imageConfig) string {
505505
p1, p2 := helpers.FileAndExt(i.rel)
506-
idStr := fmt.Sprintf("_H%s_%d", i.hash, i.osFileInfo.Size())
506+
idStr := fmt.Sprintf("_hu%s_%d", i.hash, i.osFileInfo.Size())
507507

508508
// Do not change for no good reason.
509509
const md5Threshold = 100
@@ -515,7 +515,7 @@ func (i *Image) filenameFromConfig(conf imageConfig) string {
515515
// for the different OSes to handle.
516516
if len(p1)+len(idStr)+len(p2) > md5Threshold {
517517
key = helpers.MD5String(p1 + key + p2)
518-
p1 = p1[:strings.Index(p1, "_H")]
518+
p1 = p1[:strings.Index(p1, "_hu")]
519519
} else if strings.Contains(p1, idStr) {
520520
// On scaling an already scaled image, we get the file info from the original.
521521
// Repeating the same info in the filename makes it stuttery for no good reason.

resource/image_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,27 @@ func TestImageTransform(t *testing.T) {
8282
assert.Equal(200, resizedAndRotated.Height())
8383
assertFileCache(assert, image.spec.Fs, resizedAndRotated.RelPermalink(), 125, 200)
8484

85-
assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q75_box_center.jpg", resized.RelPermalink())
85+
assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q75_box_center.jpg", resized.RelPermalink())
8686
assert.Equal(300, resized.Width())
8787
assert.Equal(200, resized.Height())
8888

8989
fitted, err := resized.Fit("50x50")
9090
assert.NoError(err)
91-
assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_e71d3649737587d41fe50793bf366f6f.jpg", fitted.RelPermalink())
91+
assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_0bda5208a94b50a6e643ad139e0dfa2f.jpg", fitted.RelPermalink())
9292
assert.Equal(50, fitted.Width())
9393
assert.Equal(31, fitted.Height())
9494

9595
// Check the MD5 key threshold
9696
fittedAgain, _ := fitted.Fit("10x20")
9797
fittedAgain, err = fittedAgain.Fit("10x20")
9898
assert.NoError(err)
99-
assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_8731035e4934a6e6e09cd10d6f04db93.jpg", fittedAgain.RelPermalink())
99+
assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_6b3034f4ca91823700bd9ff7a12acf2e.jpg", fittedAgain.RelPermalink())
100100
assert.Equal(10, fittedAgain.Width())
101101
assert.Equal(6, fittedAgain.Height())
102102

103103
filled, err := image.Fill("200x100 bottomLeft")
104104
assert.NoError(err)
105-
assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q75_box_bottomleft.jpg", filled.RelPermalink())
105+
assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q75_box_bottomleft.jpg", filled.RelPermalink())
106106
assert.Equal(200, filled.Width())
107107
assert.Equal(100, filled.Height())
108108
assertFileCache(assert, image.spec.Fs, filled.RelPermalink(), 200, 100)

0 commit comments

Comments
 (0)