php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27848 stripslashes removes single trailing slash
Submitted: 2004-04-02 20:50 UTC Modified: 2004-04-04 13:51 UTC
From: spam at pasher dot org Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.4 OS: Debian (Linux 2.4.18-bf2.4)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: spam at pasher dot org
New email:
PHP Version: OS:

 

 [2004-04-02 20:50 UTC] spam at pasher dot org
Description:
------------
The stripslashes() function strips off a single trailing \ when altering a string. I can see that according to bug report http://bugs.php.net/bug.php?id=19947 , this function is not supposed to be an exact opposite of addslashes(), but it seems as thought a string that ends in a single \ should not have that slash removed, as the slash is not actually backslashing any part of the string. The only reasoning I could see behind this is that either any slash is stripped by stripslashes, or the \0 stored at the end of the C code string to terminate it (but not actually part of the PHP code string) is considered a character being "escaped".

If stripslashes() is designed to simple strip any slash from a string, it seems like the design should be rethought a bit, as it can potentially produced undesired results.

Reproduce code:
---------------
<?
echo stripslashes("this is a test\\");
?>

Expected result:
----------------
Displays "this is a test\"

Actual result:
--------------
Displays "this is a test"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-03 13:15 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

When you create the string \\ gets converted to \, which is 
why the slash gets stripped by stripslashes(). 
 [2004-04-03 15:09 UTC] spam at pasher dot org
I don't think you quite understand the reasoning I am giving. I understand that the \\ gets converted in the string to \. The problem is the following string

this is a test\

ends up becoming

this is a test

after a run through stripslashes. Where is the logic in stripslashes stripping out ANY slash that it finds, instead of only stripping out slashes that are used to backslash another character? According to the documentation, the purpose of stripslashes is the following:

"Un-quote string quoted with addslashes()"

Why would stripslashes remove a trailing \ when there is NO way the addslashes() function would ever produce a string that ends in a single trailing \ ? This appears to be a logic error (or really an over-assumption) on the part of stripslashes().
 [2004-04-04 13:51 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Here is a proof why it works: 
 
?php 
        $a = "test\\"; 
        $b = addslashes($a); 
        $c = stripslashes($b); 
 
        var_dump($a === $c); 
?> 
 [2004-04-04 13:51 UTC] iliaa@php.net
read above. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC