resource: Avoid potential case issue in image names
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 28 Dec 2017 21:56:48 +0000 (22:56 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 28 Dec 2017 21:56:48 +0000 (22:56 +0100)
resource/image.go
resource/image_test.go

index 916f89a4869f487d18098aeada8bc7f0f863f5cd..f45c12c0b62f8f3e4371b88ef9fed1d084fb64bb 100644 (file)
@@ -503,7 +503,7 @@ func (i *Image) setBasePath(conf imageConfig) {
 
 func (i *Image) filenameFromConfig(conf imageConfig) string {
        p1, p2 := helpers.FileAndExt(i.rel)
-       idStr := fmt.Sprintf("_H%s_%d", i.hash, i.osFileInfo.Size())
+       idStr := fmt.Sprintf("_hu%s_%d", i.hash, i.osFileInfo.Size())
 
        // Do not change for no good reason.
        const md5Threshold = 100
@@ -515,7 +515,7 @@ func (i *Image) filenameFromConfig(conf imageConfig) string {
        // for the different OSes to handle.
        if len(p1)+len(idStr)+len(p2) > md5Threshold {
                key = helpers.MD5String(p1 + key + p2)
-               p1 = p1[:strings.Index(p1, "_H")]
+               p1 = p1[:strings.Index(p1, "_hu")]
        } else if strings.Contains(p1, idStr) {
                // On scaling an already scaled image, we get the file info from the original.
                // Repeating the same info in the filename makes it stuttery for no good reason.
index b29bfbddb854e862a3de7b98f2008d9b25a539e0..073a16352e48ce34b3433424c672020a2ce80213 100644 (file)
@@ -82,13 +82,13 @@ func TestImageTransform(t *testing.T) {
        assert.Equal(200, resizedAndRotated.Height())
        assertFileCache(assert, image.spec.Fs, resizedAndRotated.RelPermalink(), 125, 200)
 
-       assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q75_box_center.jpg", resized.RelPermalink())
+       assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q75_box_center.jpg", resized.RelPermalink())
        assert.Equal(300, resized.Width())
        assert.Equal(200, resized.Height())
 
        fitted, err := resized.Fit("50x50")
        assert.NoError(err)
-       assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_e71d3649737587d41fe50793bf366f6f.jpg", fitted.RelPermalink())
+       assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_0bda5208a94b50a6e643ad139e0dfa2f.jpg", fitted.RelPermalink())
        assert.Equal(50, fitted.Width())
        assert.Equal(31, fitted.Height())
 
@@ -96,13 +96,13 @@ func TestImageTransform(t *testing.T) {
        fittedAgain, _ := fitted.Fit("10x20")
        fittedAgain, err = fittedAgain.Fit("10x20")
        assert.NoError(err)
-       assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_8731035e4934a6e6e09cd10d6f04db93.jpg", fittedAgain.RelPermalink())
+       assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_6b3034f4ca91823700bd9ff7a12acf2e.jpg", fittedAgain.RelPermalink())
        assert.Equal(10, fittedAgain.Width())
        assert.Equal(6, fittedAgain.Height())
 
        filled, err := image.Fill("200x100 bottomLeft")
        assert.NoError(err)
-       assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q75_box_bottomleft.jpg", filled.RelPermalink())
+       assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q75_box_bottomleft.jpg", filled.RelPermalink())
        assert.Equal(200, filled.Width())
        assert.Equal(100, filled.Height())
        assertFileCache(assert, image.spec.Fs, filled.RelPermalink(), 200, 100)