ZF-4510: Zend_Filter_StripSlashes

Description

<?php /** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category Zend * @package Zend_Filter * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: $ */

/** * @see Zend_Filter_Interface */ require_once 'Zend/Filter/Interface.php';

/** * @category Zend * @package Zend_Filter * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Filter_StripSlashes implements Zend_Filter_Interface {

/**
 * Defined by Zend_Filter_Interface
 *
 * Returns $value without newline control characters
 *
 * @param  string $value
 * @return string
 */
public function filter ($value)
{
    return stripslashes($value);
}

}

Comments

filter function should be better with a test of magic quotes...

public function filter ($value) { if (get_magic_quotes_gpc ()) { $value = stripslashes ($value); } return $value; }

Not really.

a) magic_quotes_gpc should be disabled for ZF projects anyway. b) A filter is not only supposed for values comming from GPC, but also for example values from a web service.

Here's my version:


<?php
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';

class My_Filter_StripSlashes implements Zend_Filter_Interface
{
    /**
    * Defined by Zend_Filter_Interface
    *
    * Returns a string with slashes stripped out.
    *
    * @param string $value
    * @return string
    */
    public function filter($value)
    {
        return is_array($value)
          ? array_map(array($this, 'filter'), $value)
          : stripslashes($value);
    }
}

Curious to know if this is something that should be added to ZF? Would Zend_Filter_Callback do the job?

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.