Fixing issue where JavascriptHelper::link was generating wrong URLs when webroot is defined and appending timestapping. Fixing issue in previous commit. Fixes #5723, fixes #5045

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7851 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-11-08 12:45:00 +00:00
parent 81e2f4a044
commit e9953e3f93
3 changed files with 24 additions and 6 deletions

View file

@ -355,7 +355,7 @@ class HtmlHelper extends AppHelper {
$path = $this->webroot($path);
$url = $path;
if ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
if (strpos($path, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) {
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
}
}

View file

@ -258,20 +258,21 @@ class JavascriptHelper extends AppHelper {
}
if (strpos($url, '://') === false) {
if ($url{0} !== '/') {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
if (strpos($url, '?') === false) {
if (strpos($url, '.js') === false) {
$url .= '.js';
}
if ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
$url = $this->webroot($url);
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
}
}
$url = $this->webroot($url);
if (strpos($url, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) {
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
}
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
}

View file

@ -241,6 +241,23 @@ class JavascriptTest extends CakeTestCase {
Configure::delete('Asset.filter.js');
}
$debug = Configure::read('debug');
$webroot = $this->Javascript->webroot;
Configure::write('debug', 0);
Configure::write('Asset.timestamp', 'force');
$this->Javascript->webroot = '/testing/';
$result = $this->Javascript->link('__cake_js_test');
$this->assertPattern('/^<script[^<>]+src="\/testing\/js\/__cake_js_test\.js\?"[^<>]*>/', $result);
$this->Javascript->webroot = '/testing/longer/';
$result = $this->Javascript->link('__cake_js_test');
$this->assertPattern('/^<script[^<>]+src="\/testing\/longer\/js\/__cake_js_test\.js\?"[^<>]*>/', $result);
$this->Javascript->webroot = $webroot;
Configure::write('debug', $debug);
unlink(JS . '__cake_js_test.js');
}
/**