Skip to content

Commit 61a570b

Browse files
authored
Rework cid: images (#8966)
* Adding CID support for HtmlHelper::image() #8877 * Move cid: checking in to UrlHelper. While this does allow `cid:` prefixes to be used on all asset types, it also enables other `a-z:` prefixes to be used easily as well. Refs #8898 * Allow uppercase CID as well.
1 parent 2c1463f commit 61a570b

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/View/Helper/UrlHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function assetUrl($path, array $options = [])
120120
if (is_array($path)) {
121121
return $this->build($path, !empty($options['fullBase']));
122122
}
123-
if (strpos($path, '://') !== false) {
123+
if (strpos($path, '://') !== false || preg_match('/^[a-z]+:/i', $path)) {
124124
return $path;
125125
}
126126
if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {

tests/TestCase/View/Helper/HtmlHelperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ public function testImageTag()
336336
$result = $this->Html->image('/test/view/1.gif');
337337
$expected = ['img' => ['src' => '/test/view/1.gif', 'alt' => '']];
338338
$this->assertHtml($expected, $result);
339+
340+
$result = $this->Html->image('cid:cakephp_logo');
341+
$expected = ['img' => ['src' => 'cid:cakephp_logo', 'alt' => '']];
342+
$this->assertHtml($expected, $result);
339343
}
340344

341345
/**

tests/TestCase/View/Helper/UrlHelperTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ public function testImage()
293293

294294
$result = $this->Helper->image('dir/big+tall/image.jpg');
295295
$this->assertEquals('img/dir/big%2Btall/image.jpg', $result);
296+
297+
$result = $this->Helper->image('cid:foo.jpg');
298+
$this->assertEquals('cid:foo.jpg', $result);
299+
300+
$result = $this->Helper->image('CID:foo.jpg');
301+
$this->assertEquals('CID:foo.jpg', $result);
296302
}
297303

298304
/**

0 commit comments

Comments
 (0)