Skip to content

Commit

Permalink
Fixing detection and automatic appending of extension '.js' to urls i…
Browse files Browse the repository at this point in the history
…n call to HtmlHelper::script(). Closes #965
  • Loading branch information
ADmad committed Jul 28, 2010
1 parent d81d33f commit 6527e92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cake/libs/view/helpers/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function script($url, $options = array()) {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
if (strpos($url, '?') === false && strpos($url, '.js') === false) {
if (strpos($url, '?') === false && substr($url, -3) !== '.js') {
$url .= '.js';
}
$url = $this->assetTimestamp($this->webroot($url));
Expand Down Expand Up @@ -527,7 +527,7 @@ function scriptEnd() {
*
* {{{
* echo $html->style(array('margin' => '10px', 'padding' => '10px'), true);
*
*
* // creates
* 'margin:10px;padding:10px;'
* }}}
Expand Down
12 changes: 12 additions & 0 deletions cake/tests/cases/libs/view/helpers/html.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,24 @@ function testScript() {
);
$this->assertTags($result, $expected);

$result = $this->Html->script('test.json');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js')
);
$this->assertTags($result, $expected);

$result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')
);
$this->assertTags($result, $expected);

$result = $this->Html->script('test.json.js?foo=bar');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar')
);
$this->assertTags($result, $expected);

$result = $this->Html->script('foo');
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');

Expand Down

0 comments on commit 6527e92

Please sign in to comment.