Skip to content

Rector rule added to escape unsafe output in phtml files #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed phpcs errors and warnings because of which the merge checks wer…
…e failing
  • Loading branch information
Abhishek Jakhotiya committed Nov 16, 2023
commit e8232c63b934709eaa30fa1c363e964f30432cb8
28 changes: 18 additions & 10 deletions Magento2/Rector/Src/AddHtmlEscaperToOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,28 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// if the echo already has escapeHtml called on $block or escaper, don't do anthing
// if the echo already has escapeHtml called on $block or escaper, don't do anthing

$echoContent = $node->exprs[0];
$echoContent = $node->exprs[0];

if($echoContent instanceof Node\Expr\Variable || $echoContent instanceof Node\Expr\FuncCall){
$node->exprs[0] = new Node\Expr\MethodCall(new Node\Expr\Variable('escaper'),'escapeHtml',[new Node\Arg($echoContent)]);
return $node;
}
if ($echoContent instanceof Node\Expr\Variable || $echoContent instanceof Node\Expr\FuncCall) {
$node->exprs[0] = new Node\Expr\MethodCall(
new Node\Expr\Variable('escaper'),
'escapeHtml',
[new Node\Arg($echoContent)]
);
return $node;
}

if($echoContent instanceof Node\Expr\MethodCall && $echoContent->name != 'escapeHtml'){
if ($echoContent instanceof Node\Expr\MethodCall && $echoContent->name != 'escapeHtml') {

$node->exprs[0] = new Node\Expr\MethodCall(new Node\Expr\Variable('escaper'),'escapeHtml',[new Node\Arg($echoContent)]);
return $node;
}
$node->exprs[0] = new Node\Expr\MethodCall(
new Node\Expr\Variable('escaper'),
'escapeHtml',
[new Node\Arg($echoContent)]
);
return $node;
}

return null;
}
Expand Down