Skip to content
This repository
Browse code

Simplify how fullBase is calculated.

Using FULL_BASE_URL fixes URL generation when URL rewriting is
disabled.

Fixes #3777
  • Loading branch information...
commit 65b1a94e637c1760fe3b351fde16458219d822b0 1 parent c327bdc
Mark Story authored April 27, 2013
15  lib/Cake/Test/Case/View/HelperTest.php
@@ -659,6 +659,21 @@ public function testAssetUrl() {
659 659
 	}
660 660
 
661 661
 /**
  662
+ * Test assetUrl with no rewriting.
  663
+ *
  664
+ * @return void
  665
+ */
  666
+	public function testAssetUrlNoRewrite() {
  667
+		$this->Helper->request->addPaths(array(
  668
+			'base' => '/cake_dev/index.php',
  669
+			'webroot' => '/cake_dev/app/webroot/',
  670
+			'here' => '/cake_dev/index.php/tasks',
  671
+		));
  672
+		$result = $this->Helper->assetUrl('img/cake.icon.png', array('fullBase' => true));
  673
+		$this->assertEquals('http://localhost/cake_dev/app/webroot/img/cake.icon.png', $result);
  674
+	}
  675
+
  676
+/**
662 677
  * Test assetUrl with plugins.
663 678
  *
664 679
  * @return void
7  lib/Cake/View/Helper.php
@@ -328,12 +328,7 @@ public function assetUrl($path, $options = array()) {
328 328
 		$path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path)));
329 329
 
330 330
 		if (!empty($options['fullBase'])) {
331  
-			$base = $this->url('/', true);
332  
-			$len = strlen($this->request->webroot);
333  
-			if ($len) {
334  
-				$base = substr($base, 0, -$len);
335  
-			}
336  
-			$path = $base . $path;
  331
+			$path = rtrim(FULL_BASE_URL, '/') . '/' . ltrim($path, '/');
337 332
 		}
338 333
 		return $path;
339 334
 	}

0 notes on commit 65b1a94

Please sign in to comment.
Something went wrong with that request. Please try again.