diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php index e9feffd02..678a1df23 100644 --- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php @@ -361,7 +361,14 @@ class HtmlHelperTest extends CakeTestCase { $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' => ''))); @@ -369,6 +376,15 @@ class HtmlHelperTest extends CakeTestCase { $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' => ''))); } /** diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index a0b4aef4e..f6b17acf5 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -313,10 +313,12 @@ class Helper extends Object { $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; } }