From 65b1a94e637c1760fe3b351fde16458219d822b0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 27 Apr 2013 23:00:50 -0400 Subject: [PATCH] Simplify how fullBase is calculated. Using FULL_BASE_URL fixes URL generation when URL rewriting is disabled. Fixes #3777 --- lib/Cake/Test/Case/View/HelperTest.php | 15 +++++++++++++++ lib/Cake/View/Helper.php | 7 +------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index 0ac7d9dc6..ea92488dc 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -658,6 +658,21 @@ class HelperTest extends CakeTestCase { $this->assertEquals('foo.jpg?one=two&three=four', $result); } +/** + * Test assetUrl with no rewriting. + * + * @return void + */ + public function testAssetUrlNoRewrite() { + $this->Helper->request->addPaths(array( + 'base' => '/cake_dev/index.php', + 'webroot' => '/cake_dev/app/webroot/', + 'here' => '/cake_dev/index.php/tasks', + )); + $result = $this->Helper->assetUrl('img/cake.icon.png', array('fullBase' => true)); + $this->assertEquals('http://localhost/cake_dev/app/webroot/img/cake.icon.png', $result); + } + /** * Test assetUrl with plugins. * diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index d662d8336..2f7b79595 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -328,12 +328,7 @@ class Helper extends Object { $path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path))); if (!empty($options['fullBase'])) { - $base = $this->url('/', true); - $len = strlen($this->request->webroot); - if ($len) { - $base = substr($base, 0, -$len); - } - $path = $base . $path; + $path = rtrim(FULL_BASE_URL, '/') . '/' . ltrim($path, '/'); } return $path; }