|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-09-06 11:07 UTC] itsursujit at gmail dot com
Description:
------------
I encountered this issue when I tried to sanitize urlencoded variables. Here are the steps with expected and actual results:
Step 1: assign string to variable with encoded characters
$x="I've some comment";
Step 2: decode the variable using `urldecode()`
$decoded=urldecode($x); //result: I've some comment;
echo $decoded;
EXPECTED RESULT: I've some comment
ACTUAL RESULT: I've some comment
Step 3: filter above decoded data and echo the result
echo trim(filter_var(stripslashes($decoded), FILTER_SANITIZE_SPECIAL_CHARS));
EXPECTED RESULT: I've some comment
ACTUAL RESULT: I've some comment
Step 4: filter above raw string and echo the result
echo trim(filter_var(stripslashes("I've some comment"), FILTER_SANITIZE_SPECIAL_CHARS));
EXPECTED RESULT: I've some comment
ACTUAL RESULT: I've some comment
I think the Step 3 has some bug.
Test script:
---------------
<?php
$x="I've some comment";
$decoded=urldecode($x); //result: I've some comment;
echo $decoded; //result: I've some comment;
echo "\n";
echo trim(filter_var(stripslashes($decoded), FILTER_SANITIZE_SPECIAL_CHARS));
echo "\n";
echo trim(filter_var(stripslashes("I've some comment"), FILTER_SANITIZE_SPECIAL_CHARS));
Expected result:
----------------
$x="I've some comment";
$decoded=urldecode($x); //result: I've some comment;
echo $decoded;
EXPECTED RESULT: I've some comment
echo trim(filter_var(stripslashes($decoded), FILTER_SANITIZE_SPECIAL_CHARS));
EXPECTED RESULT: I've some comment
echo trim(filter_var(stripslashes("I've some comment"), FILTER_SANITIZE_SPECIAL_CHARS));
EXPECTED RESULT: I've some comment
Actual result:
--------------
$x="I've some comment";
$decoded=urldecode($x); //result: I've some comment;
echo $decoded;
ACTUAL RESULT: I've some comment
echo trim(filter_var(stripslashes($decoded), FILTER_SANITIZE_SPECIAL_CHARS));
ACTUAL RESULT: I've some comment
echo trim(filter_var(stripslashes("I've some comment"), FILTER_SANITIZE_SPECIAL_CHARS));
ACTUAL RESULT: I've some comment
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 05:00:01 2025 UTC |
' is not a URL-encoded ("percent-encoded") apostrophe. It is an HTML entity.