Adding quotes around JSON keys (Ticket #702)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3437 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-08-28 15:40:19 +00:00
parent 00df232f9e
commit 05d954a5bf

View file

@ -75,16 +75,24 @@ class JavascriptHelper extends Helper{
* Returns a JavaScript include tag (SCRIPT element)
*
* @param string $url URL to JavaScript file.
* @param boolean $inline If true, the <script /> tag will be printed inline,
* otherwise it will be printed in the <head />
* @return string
*/
function link($url) {
function link($url, $inline = true) {
if (strpos($url, '.') === false && strpos($url, '?') === false) {
$url .= '.js';
}
if (strpos($url, '://') === false) {
$url = $this->webroot . $this->themeWeb . JS_URL . $url;
}
return sprintf($this->tags['javascriptlink'], $url);
$out = $this->output(sprintf($this->tags['javascriptlink'], $url));
if ($inline) {
return $out;
} else {
$this->view->addScript($out);
}
}
/**
* Returns a JavaScript include tag for an externally-hosted script
@ -288,16 +296,16 @@ class JavascriptHelper extends Helper{
if (is_array($val) || is_object($val)) {
$val = $this->object($val, false, '', '', $stringKeys, $quoteKeys, $q);
} else {
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val)) || ($quoteKeys && in_array($key, $stringKeys)) || (!$quoteKeys && !in_array($key, $stringKeys))) {
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val)) || ($quoteKeys && in_array($key, $stringKeys)) || (!$quoteKeys && !in_array($key, $stringKeys)) && $val !== null) {
$val = $q . $this->escapeString($val) . $q;
}
if (trim($val) == '') {
if ($val == null) {
$val = 'null';
}
}
if (!$numeric) {
$val = $key . ':' . $val;
$val = $q . $key . $q . ':' . $val;
}
$out[] = $val;