Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit e0cc17e

Browse files
authored
Merge pull request #188 from skie/2.0
fix url generation in cake if hash is empty
2 parents e566dd7 + 709582f commit e0cc17e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/View/Helper/ImageHelper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ protected function _getHash($version, $image) {
9292
public function imageUrl($image, $version = null, $options = []) {
9393
$fileInfo = pathinfo($image['path']);
9494
$hash = $this->_getHash($version, $image);
95-
$version = $fileInfo['dirname'] . DS . $fileInfo['filename'] . '.' . $hash;
95+
$version = $fileInfo['dirname'] . DS . $fileInfo['filename'];
96+
if ($hash !== null) {
97+
$version .= '.' . $hash;
98+
}
9699

97100
if (!empty($fileInfo['extension'])) {
98101
$version .= '.' . $fileInfo['extension'];

tests/TestCase/View/Helper/ImageHelperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public function testImageUrl() {
8181

8282
$result = $this->Image->imageUrl($image, 't150', ['pathPrefix' => '/src/']);
8383
$this->assertEquals('/src/test/path/testimage.c3f33c2a.jpg', $result);
84+
85+
$result = $this->Image->imageUrl($image, null, ['pathPrefix' => '/src/']);
86+
$this->assertEquals('/src/test/path/testimage.jpg', $result);
8487
}
8588

8689
/**

0 commit comments

Comments
 (0)