Skip to content

Commit

Permalink
Remove purifyHtmlString from OcCookie
Browse files Browse the repository at this point in the history
  This method uses HTMLPurifier to clean up input text with html tags but this is take a lot of memory.
  OCCookie can use just htmlspecialchars instead (it saves a half of the memory of each OCPL code call as asmost always OCCookie is in use.
  • Loading branch information
kojoty committed Oct 16, 2021
1 parent 825cd3a commit 01d9ead
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/Utils/Debug/Debug.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
namespace src\Utils\Debug;

use Error;
use Throwable;


class Debug {

/**
Expand Down Expand Up @@ -57,4 +55,21 @@ public static function dumpToLog($var, $message = null)
$result .= var_export($var, TRUE);
error_log($result);
}

/**
* Function to print memory usage to log.
* Best usage: Debug::memUsage(__FILE__.':'.__LINE__)
* Shows memory usage and diff from the last call.
*
* @param string $placeInCode - identifier to add to the string in log
*/
public static function memUsage($placeInCode = "?"): void
{
static $lastMemUsage = 0;
$currMemUsage = memory_get_usage();
self::errorLog(
$placeInCode.": ".round($currMemUsage/1024, 2)." / ".round(($currMemUsage-$lastMemUsage)/1024, 2), false);
$lastMemUsage = $currMemUsage;
}

}
5 changes: 3 additions & 2 deletions src/Utils/Uri/OcCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace src\Utils\Uri;

use src\Utils\Debug\Debug;
use src\Utils\Text\UserInputFilter;
use src\Models\User\UserAuthorization;

class OcCookie
Expand All @@ -15,6 +14,7 @@ class OcCookie

/**
* Set data in cookie uder the $key
* NOTE: htmlspecialchars is running when value is read from cookie
*
* @param string $key
* @param mixed $value
Expand All @@ -35,6 +35,7 @@ public static function set($key, $value, $saveToHeaderNow = false)

/**
* Get data from cookie stored under $key
* PLEASE NOTE that puryfing is done by default (by htmlspecialchars).
*
* @param string $key
* @return mixed | null - null if no data
Expand All @@ -44,7 +45,7 @@ public static function get($key, $skipPurifying = false)
$data = self::getOcCookieData(); // init oc data
if (isset($data->$key)) {
if (! $skipPurifying) {
return UserInputFilter::purifyHtmlString($data->$key);
return htmlspecialchars($data->$key);
} else {
return $data->$key;
}
Expand Down

0 comments on commit 01d9ead

Please sign in to comment.