Adding fix for , Sanitize::escape() fails for numbers.

Added test for .
Corrected header files in tests

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5428 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-07-09 17:02:55 +00:00
parent 016f5a952b
commit 1df4249d54
8 changed files with 141 additions and 86 deletions

View file

@ -72,9 +72,12 @@ class Sanitize{
*/ */
function escape($string, $connection = 'default') { function escape($string, $connection = 'default') {
$db = ConnectionManager::getDataSource($connection); $db = ConnectionManager::getDataSource($connection);
$value = substr($db->value($string), 1); if(is_numeric($string)) {
$value = substr($value, 0, -1); return $string;
return $value; }
$string = substr($db->value($string), 1);
$string = substr($string, 0, -1);
return $string;
} }
/** /**
* Returns given string safe for display as HTML. Renders entities. * Returns given string safe for display as HTML. Renders entities.

View file

@ -7,32 +7,31 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP Test Suite <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * Copyright 2005-2007, Cake Software Foundation, Inc.
* Author(s): Larry E. Masters aka PhpNut <phpnut@gmail.com> * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @author Larry E. Masters aka PhpNut <phpnut@gmail.com> * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @copyright Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @link http://www.phpnut.com/projects/ * @package cake.tests
* @package test_suite * @subpackage cake.tests.cases.libs
* @subpackage test_suite.cases.app * @since CakePHP(tm) v 1.2.0.4206
* @since CakePHP Test Suite v 1.0.0.0 * @version $Revision$
* @version $Revision$ * @modifiedby $LastChangedBy$
* @modifiedby $LastChangedBy$ * @lastmodified $Date$
* @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
uses('file'); uses('file');
/** /**
* Short description for class. * Short description for class.
* *
* @package test_suite * @package cake.tests
* @subpackage test_suite.cases.libs * @subpackage cake.tests.cases.libs
* @since CakePHP Test Suite v 1.0.0.0
*/ */
class FileTest extends UnitTestCase { class FileTest extends UnitTestCase {

View file

@ -7,32 +7,31 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP Test Suite <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * Copyright 2005-2007, Cake Software Foundation, Inc.
* Author(s): Larry E. Masters aka PhpNut <phpnut@gmail.com> * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @author Larry E. Masters aka PhpNut <phpnut@gmail.com> * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @copyright Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @link http://www.phpnut.com/projects/ * @package cake.tests
* @package test_suite * @subpackage cake.tests.cases.libs
* @subpackage test_suite.cases.app * @since CakePHP(tm) v 1.2.0.4206
* @since CakePHP Test Suite v 1.0.0.0 * @version $Revision$
* @version $Revision$ * @modifiedby $LastChangedBy$
* @modifiedby $LastChangedBy$ * @lastmodified $Date$
* @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
uses('folder'); uses('folder');
/** /**
* Short description for class. * Short description for class.
* *
* @package test_suite * @package cake.tests
* @subpackage test_suite.cases.libs * @subpackage cake.tests.cases.libs
* @since CakePHP Test Suite v 1.0.0.0
*/ */
class FolderTest extends UnitTestCase { class FolderTest extends UnitTestCase {

View file

@ -7,30 +7,31 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP Test Suite <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * Copyright 2005-2007, Cake Software Foundation, Inc.
* Author(s): Larry E. Masters aka PhpNut <phpnut@gmail.com> * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @author Larry E. Masters aka PhpNut <phpnut@gmail.com> * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @copyright Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @link http://www.phpnut.com/projects/ * @package cake.tests
* @package test_suite * @subpackage cake.tests.cases.libs
* @subpackage test_suite.cases.app * @since CakePHP(tm) v 1.2.0.4206
* @since CakePHP Test Suite v 1.0.0.0 * @version $Revision$
* @version $Revision$ * @modifiedby $LastChangedBy$
* @modifiedby $LastChangedBy$ * @lastmodified $Date$
* @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
uses('http_socket'); uses('http_socket');
/** /**
* Enter description here... * Short description for class.
* *
* @package cake.tests
* @subpackage cake.tests.cases.libs
*/ */
class HttpSocketTest extends UnitTestCase { class HttpSocketTest extends UnitTestCase {

View file

@ -7,35 +7,34 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP Test Suite <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * Copyright 2005-2007, Cake Software Foundation, Inc.
* Author(s): Larry E. Masters aka PhpNut <phpnut@gmail.com> * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @author Larry E. Masters aka PhpNut <phpnut@gmail.com> * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @copyright Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @link http://www.phpnut.com/projects/ * @package cake.tests
* @package test_suite * @subpackage cake.tests.cases.libs
* @subpackage test_suite.cases.app * @since CakePHP(tm) v 1.2.0.4206
* @since CakePHP Test Suite v 1.0.0.0 * @version $Revision$
* @version $Revision$ * @modifiedby $LastChangedBy$
* @modifiedby $LastChangedBy$ * @lastmodified $Date$
* @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
uses('inflector'); uses('inflector');
/** /**
* Short description for class. * Short description for class.
* *
* @package test_suite * @package cake.tests
* @subpackage test_suite.cases.libs * @subpackage cake.tests.cases.libs
* @since CakePHP Test Suite v 1.0.0.0
*/ */
class InflectorTest extends UnitTestCase { class InflectorTest extends UnitTestCase {
var $Inflector = null; var $Inflector = null;
function setUp() { function setUp() {

View file

@ -0,0 +1,55 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.5428
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
uses('sanitize');
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs
*/
class SanitizeTest extends UnitTestCase {
function testEscapeAlphaNumeric() {
$resultAlpha = Sanitize::escape('abc', 'default');
$this->assertEqual($resultAlpha, 'abc');
$resultNumeric = Sanitize::escape('123', 'default');
$this->assertEqual($resultNumeric, '123');
$resultNumeric = Sanitize::escape(1234, 'default');
$this->assertEqual($resultNumeric, 1234);
$resultNumeric = Sanitize::escape(1234.23, 'default');
$this->assertEqual($resultNumeric, 1234.23);
$resultNumeric = Sanitize::escape('#1234.23', 'default');
$this->assertEqual($resultNumeric, '#1234.23');
}
}
?>

View file

@ -7,32 +7,31 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP Test Suite <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * Copyright 2005-2007, Cake Software Foundation, Inc.
* Author(s): Larry E. Masters aka PhpNut <phpnut@gmail.com> * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @author Larry E. Masters aka PhpNut <phpnut@gmail.com> * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @copyright Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @link http://www.phpnut.com/projects/ * @package cake.tests
* @package test_suite * @subpackage cake.tests.cases.libs
* @subpackage test_suite.cases.app * @since CakePHP(tm) v 1.2.0.4206
* @since CakePHP Test Suite v 1.0.0.0 * @version $Revision$
* @version $Revision$ * @modifiedby $LastChangedBy$
* @modifiedby $LastChangedBy$ * @lastmodified $Date$
* @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
uses('session'); uses('session');
/** /**
* Short description for class. * Short description for class.
* *
* @package test_suite * @package cake.tests
* @subpackage test_suite.cases.libs * @subpackage cake.tests.cases.libs
* @since CakePHP Test Suite v 1.0.0.0
*/ */
class SessionTest extends UnitTestCase { class SessionTest extends UnitTestCase {

View file

@ -19,7 +19,7 @@
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc. * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests * @package cake.tests
* @subpackage cake.tests.cases.libs.model * @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.4206 * @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$ * @version $Revision$
* @modifiedby $LastChangedBy$ * @modifiedby $LastChangedBy$
@ -33,8 +33,8 @@ uses('set');
/** /**
* UnitTestCase for the Set class * UnitTestCase for the Set class
* *
* @package cake * @package cake.tests
* @subpackage cake.cake.libs * @subpackage cake.tests.cases.libs
*/ */
class SetTest extends UnitTestCase { class SetTest extends UnitTestCase {