Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing detection and automatic appending of extension '.js' to urls i…

…n call to HtmlHelper::script(). Closes #965
  • Loading branch information...
commit 6527e9269aa14433c3b30f4c810e1b52ef89da34 1 parent d81d33f
@ADmad ADmad authored
View
4 cake/libs/view/helpers/html.php
@@ -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));
@@ -527,7 +527,7 @@ function scriptEnd() {
*
* {{{
* echo $html->style(array('margin' => '10px', 'padding' => '10px'), true);
- *
+ *
* // creates
* 'margin:10px;padding:10px;'
* }}}
View
12 cake/tests/cases/libs/view/helpers/html.test.php
@@ -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');
Please sign in to comment.
Something went wrong with that request. Please try again.