Comments (5)
We missed this deprecation in the code. Here is the fix for it:
Good information related to this issue:
from magento-lts.
File: /app/code/core/Mage/GiftMessage/Block/Message/Inline.php on line 246.
/**
* Return escaped value
*
* @param string $value
* @param string $defaultValue
* @return string
*/
public function getEscaped($value, $defaultValue = '')
{
return $this->escapeHtml(trim($value) != '' ? $value : $defaultValue);
}
How would you like to proceed for this part of the code to fix this issue?
VARIANT 1
public function getEscaped($value, $defaultValue = '')
{
$value = $value ?? '';
return $this->escapeHtml(trim($value) != '' ? $value : $defaultValue);
}
VARIANT 2
public function getEscaped($value, $defaultValue = '')
{
return $this->escapeHtml(trim($value ?? '') != '' ? $value : $defaultValue);
}
VARIANT 3
public function getEscaped($value, $defaultValue = '')
{
return $this->escapeHtml((string) trim($value) != '' ? $value : $defaultValue);
}
VARIANT 4
public function getEscaped($value, $defaultValue = '')
{
return $this->escapeHtml((empty($value) ? '' : trim($value)) != '' ? $value : $defaultValue);
}
VARIANT 5
public function getEscaped($value, $defaultValue = '')
{
if (is_string($value)) {
return $this->escapeHtml(trim($value) != '' ? $value : $defaultValue);
}
}
All the variants above solve the issue. Any feedback is welcome.
from magento-lts.
I'd do this:
public function getEscaped($value, $defaultValue = '')
{
if ($value === null || strlen($value) == 0) return $defaultValue;
return $this->escapeHtml(trim($value));
}
it seems to me easier to read and should give a tiny fraction more performance because it doesn't call functions that are not needed with an empty string.
PS: I think variant 5 doesn't work because it never returns the $defaultvalue for an empty $value
from magento-lts.
Your version is fine too. It is good to discuss before proposing a PR. such a change must take into account the non-alteration of performance, the ease of reading the code.
I would use { } with the condition, as if this has been done before (I am remembering well).
public function getEscaped($value, $defaultValue = '')
{
if ($value === null || strlen($value) == 0) {
return $defaultValue;
}
return $this->escapeHtml(trim($value));
}
To Be Discussed
- I searched the OpenMage code for the following string escapeHtml(trim($. I found a few more, but I didn't investigate further. Do you think we should change in different PR's those as a preventive measure?
- Such errors could not be automatically identified in the source code of a workflow?
from magento-lts.
right about the brakets, phpcs would have complained ehhehe
- nice idea, I think it could also be one single PR, expecially if it's not many places to fix
- I don't know enough about this but probably PHPStan with a "higher level" configuration would detect those (among many many other errors) but we couldn't raise the level because of the many errors it triggers...
from magento-lts.
Related Issues (20)
- Fatal error: Uncaught Error: Call to a member function addData() on null HOT 2
- Deprecated functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
- Deprecated functionality: strlen(): Passing null to parameter #1 ($string) of type string is deprecated
- Fatal error: Uncaught Error: Call to a member function setOnclick() on false HOT 2
- Deprecated functionality: nl2br(): Passing null to parameter #1 ($string) of type string is deprecated
- Deprecated functionality: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated
- incorrect currency value HOT 4
- Use redis for session HOT 5
- Customer information missing after 19.5.3 -> 20.5.0 upgrade HOT 7
- Creating an order for a new registered customer - Required email address issue HOT 1
- Recaptcha HOT 2
- Payment and Shipping not selectable in backend (customer) order, but in frontend. HOT 1
- OpenMage (19.x and 20.x) appears incompatible with Amasty extensions
- onepage/billing.phtml required still displayed after removed. HOT 3
- Upgrading from 19.4.x to 20: recurring data is not saved
- Customers on online not showing HOT 3
- A recurring product is not calculated correctly in the cart HOT 3
- Long running queries presumably from layered navigation HOT 13
- PHP Error in frontend with improper request params HOT 2
- shardj/zf1-future patches all fail during composer install HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magento-lts.