Permalink
Browse files

Fix double base dir in image() with fullBase.

Fixes #2991
  • Loading branch information...
markstory committed Jul 4, 2012
1 parent 2237386 commit e61f636bc7e6d9bcc53ed2dba7f4041bfd7a42dc
Showing with 21 additions and 3 deletions.
  1. +16 −0 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +5 −3 lib/Cake/View/Helper.php
@@ -361,14 +361,30 @@ public function testImageTag() {
$result = $this->Html->image('test.gif?one=two&three=four');
$this->assertTags($result, array('img' => array('src' => 'img/test.gif?one=two&three=four', 'alt' => '')));
}
/**
* Test that image() works with fullBase and a webroot not equal to /
*
* @return void
*/
public function testImageWithFullBase() {
$result = $this->Html->image('test.gif', array('fullBase' => true));
$here = $this->Html->url('/', true);
$this->assertTags($result, array('img' => array('src' => $here . 'img/test.gif', 'alt' => '')));
$result = $this->Html->image('sub/test.gif', array('fullBase' => true));
$here = $this->Html->url('/', true);
$this->assertTags($result, array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => '')));
$request = $this->Html->request;
$request->webroot = '/myproject/';
$request->base = '/myproject';
Router::setRequestInfo($request);
$result = $this->Html->image('sub/test.gif', array('fullBase' => true));
$here = $this->Html->url('/', true);
$this->assertTags($result, array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => '')));
}
/**
View
@@ -313,10 +313,12 @@ public function assetUrl($path, $options = array()) {
$path = h($this->assetTimestamp($this->webroot($path)));
if (!empty($options['fullBase'])) {
if ($path[0] == '/') {
$path = substr($path, 1);
$base = $this->url('/', true);
$len = strlen($this->request->webroot);
if ($len) {
$base = substr($base, 0, -$len);
}
$path = $this->url('/', true) . $path;
$path = $base . $path;
}
}

0 comments on commit e61f636

Please sign in to comment.