#44956 [Com]: stripslashes() removes slashes not added by addslashes()

From: Date: Fri, 09 May 2008 16:43:05 +0000
Subject: #44956 [Com]: stripslashes() removes slashes not added by addslashes()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124863@lists.php.net to get a copy of this message
ID: 44956 Comment by: c dot onogol at gmail dot com Reported By: webmaster at drk dot com dot ar Status: Open Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 5.2.6 New Comment: I realized my previous comment needs some clarification. The function does work when you do: assert($a == stripslashes(addslashes($a))) This function breaks strings when not used in conjunction with addslashes(). By simply skipping single backslashes you can make this function safe to use in all cases. Wouldn't it be an enhancement if you made it so single slashes are simply skipped, since most likely they have not been used with addslashes()? Previous Comments: ------------------------------------------------------------------------ [2008-05-09 15:56:30] c dot onogol at gmail dot com I agree. The documentation makes you think it's the exact opposite of addslashes(), both in the function description and its return values (which happen to be explicitly listed, and there's no mention of removing single slashes that are not escaping anything). There's no string that produces "this \ that" after a call to addslashes(). addslashes("this that") would never output "this \ that"... The doc says clearly "Un-quotes a quoted string", it's clear its purpose is to run it on strings to be inserted in a DB, why would it remove single slashes? ------------------------------------------------------------------------ [2008-05-09 15:43:35] webmaster at drk dot com dot ar Description: ------------ stripslashes() removes slashes not added by addslashes() I expect a function to do what is described in the first line of its documentation. As published in this site "un-quotes strings quoted with addslashes()" It is water clear this functions isn't working as expected. As it shouldn't remove any slash that addslashes() wouldn't add. In example, a slash before a space won't be added by addslashes() and mustn't be removed by stripslashes() You can refuse to correct the code. In that case, which I consider most useless, you ought to correct the documentation. I ask myself won't be useful a function which undoes what addslashes() does? Reproduce code: --------------- <? $str = "the first \ should stay. it\'s the \"right\" case"; $str = stripslashes($str); var_dump($str); ?> Expected result: ---------------- "the first \ should stay. it's the "right" case" Actual result: -------------- "the first should stay. it's the "right" case" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44956&edit=1

« previous php.bugs (#124863) next »