Skip to content

Commit

Permalink
Rework cid: images (#8966)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
markstory committed Jun 21, 2016
1 parent 2c1463f commit 61a570b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/View/Helper/UrlHelper.php
Expand Up @@ -120,7 +120,7 @@ public function assetUrl($path, array $options = [])
if (is_array($path)) {
return $this->build($path, !empty($options['fullBase']));
}
if (strpos($path, '://') !== false) {
if (strpos($path, '://') !== false || preg_match('/^[a-z]+:/i', $path)) {
return $path;
}
if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/View/Helper/HtmlHelperTest.php
Expand Up @@ -336,6 +336,10 @@ public function testImageTag()
$result = $this->Html->image('/test/view/1.gif');
$expected = ['img' => ['src' => '/test/view/1.gif', 'alt' => '']];
$this->assertHtml($expected, $result);

$result = $this->Html->image('cid:cakephp_logo');
$expected = ['img' => ['src' => 'cid:cakephp_logo', 'alt' => '']];
$this->assertHtml($expected, $result);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase/View/Helper/UrlHelperTest.php
Expand Up @@ -293,6 +293,12 @@ public function testImage()

$result = $this->Helper->image('dir/big+tall/image.jpg');
$this->assertEquals('img/dir/big%2Btall/image.jpg', $result);

$result = $this->Helper->image('cid:foo.jpg');
$this->assertEquals('cid:foo.jpg', $result);

$result = $this->Helper->image('CID:foo.jpg');
$this->assertEquals('CID:foo.jpg', $result);
}

/**
Expand Down

0 comments on commit 61a570b

Please sign in to comment.