Bug #76950 [Opn]: trim not working

From: Date: Sat, 29 Sep 2018 20:53:41 +0000
Subject: Bug #76950 [Opn]: trim not working
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217299@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76950&edit=1

 ID:                 76950
 Updated by:         requinix@php.net
 Reported by:        tobias at tromm dot no-ip dot org
 Summary:            trim not working
 Status:             Open
 Type:               Bug
 Package:            *General Issues
 Operating System:   Windows Server 2016
 PHP Version:        7.2.10
 Block user comment: N
 Private report:     N

 New Comment:

<?php

   $apelido = "           David           ";

   echo "Given String: \"".$apelido."\"<br><br>";
   echo "Given String with the use of php trim function:
\"".trim($apelido)."\"<br><br>";

   echo "Now we will check the ASCII table to check wich character are being
used:<br><br>";

   for ($cont=0; $cont <strlen($apelido); $cont++){
      echo "ORD: ".ord($apelido[$cont])."<br>";
   }

   $fazer = 1;

   do {
      $fazer = 0;

      //Check the beginning of the string
      if ($apelido[0] == chr(32) OR $apelido[0] == chr(194) OR $apelido[0] == chr(160)) {
         $fazer = 1;
         $apelido = ltrim($apelido, chr(32));
         $apelido = ltrim($apelido, chr(194));
         $apelido = ltrim($apelido, chr(160));
      }

      //Check the end of the string
      if ($apelido[strlen($apelido)-1] == chr(32) OR $apelido[strlen($apelido)-1] == chr(194) OR
$apelido[strlen($apelido)-1] == chr(160)) {
         $fazer = 1;
         $apelido = rtrim($apelido, chr(32));
         $apelido = rtrim($apelido, chr(194));
         $apelido = rtrim($apelido, chr(160));
      }

} while ($fazer == 1);

   echo "<br>Result String:
\"".$apelido."\"<br><br>";

?>


Previous Comments:
------------------------------------------------------------------------
[2018-09-29 20:52:00] tobias at tromm dot no-ip dot org

I am afraid that if I copy the script here the characters will be converted and the result will
change.

Thas why I provide you a zip.

------------------------------------------------------------------------
[2018-09-29 20:48:47] tobias at tromm dot no-ip dot org

fix title

------------------------------------------------------------------------
[2018-09-29 20:46:52] requinix@php.net

If you have a repro script then include it in the report. Don't link us a .zip to download and
open.

------------------------------------------------------------------------
[2018-09-29 20:36:23] tobias at tromm dot no-ip dot org

Description:
------------
Hi.

The function rtrim is not working correctly if user uses ASCII table to cheat the system.

Please check the full example I am given with some fix [probably there is a better way to fix it,
but, it is working].


Test script:
---------------
https://www.papinho.com/PHP_bug.zip

Expected result:
----------------
Result String: "David"

This is the result with my fix script.

Actual result:
--------------
Given String: "           David           "

Given String with the use of php trim function: "          David          "


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=76950&edit=1


Thread (11 messages)

« previous php.bugs (#217299) next »