From 80b1eb4ee2a4cc771d3e43ea5cf7150e2e8abae3 Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 28 Oct 2009 23:44:30 -0500 Subject: [PATCH 1/3] Merging fix for invalid characters in cookie name. Fixes --- cake/libs/controller/components/cookie.php | 112 +++++++-------------- 1 file changed, 37 insertions(+), 75 deletions(-) diff --git a/cake/libs/controller/components/cookie.php b/cake/libs/controller/components/cookie.php index 4d147026d..5dbe38e67 100644 --- a/cake/libs/controller/components/cookie.php +++ b/cake/libs/controller/components/cookie.php @@ -205,31 +205,25 @@ class CookieComponent extends Object { if (is_null($encrypt)) { $encrypt = true; } - $this->__encrypted = $encrypt; $this->__expire($expires); + + if (!is_array($key)) { + $key = array($key => $value); + } - if (!is_array($key) && $value !== null) { - $name = $this->__cookieVarNames($key); - - if (count($name) > 1) { - $this->__values[$name[0]][$name[1]] = $value; - $this->__write("[" . $name[0] . "][" . $name[1] . "]", $value); + foreach ($key as $name => $value) { + if (strpos($name, '.') === false) { + $this->__values[$name] = $value; + $this->__write(".$name", $value); + } else { - $this->__values[$name[0]] = $value; - $this->__write("[" . $name[0] . "]", $value); - } - } else { - foreach ($key as $names => $value) { - $name = $this->__cookieVarNames($names); - - if (count($name) > 1) { - $this->__values[$name[0]][$name[1]] = $value; - $this->__write("[" . $name[0] . "][" . $name[1] . "]", $value); - } else { - $this->__values[$name[0]] = $value; - $this->__write("[" . $name[0] . "]", $value); + $names = explode('.', $name, 2); + if (!isset($this->__values[$names[0]])) { + $this->__values[$names[0]] = array(); } + $this->__values[$names[0]] = Set::insert($this->__values[$names[0]], $names[1], $value); + $this->__write("." . implode('.', $names), $value); } } $this->__encrypted = true; @@ -253,22 +247,19 @@ class CookieComponent extends Object { if (is_null($key)) { return $this->__values; } - $name = $this->__cookieVarNames($key); - - if (count($name) > 1) { - if (isset($this->__values[$name[0]])) { - if (isset($this->__values[$name[0]][$name[1]])) { - return $this->__values[$name[0]][$name[1]]; - } - } - return null; - } else { - if (isset($this->__values[$name[0]])) { - $value = $this->__values[$name[0]]; - return $value; - } + + if (strpos($key, '.') !== false) { + $names = explode('.', $key, 2); + $key = $names[0]; + } + if (!isset($this->__values[$key])) { return null; } + + if (!empty($names[1])) { + return Set::extract($this->__values[$key], $names[1]); + } + return $this->__values[$key]; } /** @@ -296,23 +287,14 @@ class CookieComponent extends Object { if (empty($this->__values)) { $this->read(); } - $name = $this->__cookieVarNames($key); - if (count($name) > 1) { - if (isset($this->__values[$name[0]])) { - $this->__delete("[" . $name[0] . "][" . $name[1] . "]"); - unset($this->__values[$name[0]][$name[1]]); - } - } else { - if (isset($this->__values[$name[0]])) { - if (is_array($this->__values[$name[0]])) { - foreach ($this->__values[$name[0]] as $key => $value) { - $this->__delete("[" . $name[0] . "][" . $key . "]"); - } - } - $this->__delete("[" . $name[0] . "]"); - unset($this->__values[$name[0]]); - } + if (strpos($key, '.') === false) { + unset($this->__values[$key]); + $this->__delete(".$key"); + return; } + $names = explode('.', $key, 2); + $this->__values[$names[0]] = Set::remove($this->__values[$names[0]], $names[1]); + $this->__delete("." . implode('.', $names)); } /** @@ -333,11 +315,11 @@ class CookieComponent extends Object { if (is_array($value)) { foreach ($value as $key => $val) { unset($this->__values[$name][$key]); - $this->__delete("[$name][$key]"); + $this->__delete(".$name.$key"); } } unset($this->__values[$name]); - $this->__delete("[$name]"); + $this->__delete(".$name"); } } @@ -386,7 +368,7 @@ class CookieComponent extends Object { * @access private */ function __write($name, $value) { - setcookie($this->name . "$name", $this->__encrypt($value), $this->__expires, $this->path, $this->domain, $this->secure); + setcookie($this->name . $name, $this->__encrypt($value), $this->__expires, $this->path, $this->domain, $this->secure); if (!is_null($this->__reset)) { $this->__expires = $this->__reset; @@ -420,7 +402,7 @@ class CookieComponent extends Object { $type = $this->__type; $value = "Q2FrZQ==." .base64_encode(Security::$type($value, $this->key)); } - return($value); + return $value; } /** @@ -455,27 +437,7 @@ class CookieComponent extends Object { } } } - - return($decrypted); - } - -/** - * Creates an array from the $name parameter which allows the dot notation - * similar to one used by Session and Configure classes - * - * @param string $name Name with or without dot notation - * @return array Extracted names - * @access private - */ - function __cookieVarNames($name) { - if (is_string($name)) { - if (strpos($name, ".")) { - $name = explode(".", $name); - } else { - $name = array($name); - } - } - return $name; + return $decrypted; } /** From 7bead5df30cebfb8618b93ac538323f0fc8eba6f Mon Sep 17 00:00:00 2001 From: phpnut Date: Fri, 30 Oct 2009 14:43:52 -0500 Subject: [PATCH 2/3] Fixing catalog() to return 3 char matches --- cake/libs/l10n.php | 2 ++ cake/tests/cases/libs/l10n.test.php | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/cake/libs/l10n.php b/cake/libs/l10n.php index ceab772c5..b0b291094 100644 --- a/cake/libs/l10n.php +++ b/cake/libs/l10n.php @@ -474,6 +474,8 @@ class L10n extends Object { } else if (is_string($language)) { if (isset($this->__l10nCatalog[$language])) { return $this->__l10nCatalog[$language]; + } else if (isset($this->__l10nMap[$language]) && isset($this->__l10nCatalog[$this->__l10nMap[$language]])) { + return $this->__l10nCatalog[$this->__l10nMap[$language]]; } return false; } diff --git a/cake/tests/cases/libs/l10n.test.php b/cake/tests/cases/libs/l10n.test.php index e3f0afb6d..3afd1ab4f 100644 --- a/cake/tests/cases/libs/l10n.test.php +++ b/cake/tests/cases/libs/l10n.test.php @@ -981,6 +981,17 @@ class L10nTest extends CakeTestCase { 'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8') ); $this->assertEqual($result, $expected); + + $result = $l10n->catalog(array('eng', 'deu', 'zho', 'rum', 'zul', 'yid')); + $expected = array( + 'eng' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8'), + 'deu' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8'), + 'zho' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8'), + 'rum' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8'), + 'zul' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8'), + 'yid' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8') + ); + $this->assertEqual($result, $expected); } } ?> \ No newline at end of file From bc26a6ab67bd5bab11646ddd025aa5dbdc5aea45 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Oct 2009 22:03:23 -0400 Subject: [PATCH 3/3] Updating fixture task to change when CakeSchema is loaded to fix issues with errors being generated when baking new projects. Fixes #226 --- cake/console/libs/tasks/fixture.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index f91b6d3c4..dc55c8720 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -73,9 +73,6 @@ class FixtureTask extends Shell { function __construct(&$dispatch) { parent::__construct($dispatch); $this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS; - if (!class_exists('CakeSchema')) { - App::import('Model', 'CakeSchema', false); - } } /** @@ -85,6 +82,10 @@ class FixtureTask extends Shell { * @access public */ function execute() { + if (!class_exists('CakeSchema')) { + App::import('Model', 'CakeSchema', false); + } + if (empty($this->args)) { $this->__interactive(); }