Skip to content

Commit

Permalink
ModifierNode: added $sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 18, 2022
1 parent b185e1c commit 227d835
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Latte/Compiler/Nodes/Php/ModifierNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(
/** @var FilterNode[] */
public array $filters,
public bool $escape = false,
public bool $sanitize = true,
public ?Position $position = null,
) {
(function (FilterNode ...$args) {})(...$filters);
Expand All @@ -46,26 +47,28 @@ public function print(PrintContext $context): string

public function printSimple(PrintContext $context, string $expr): string
{
$escape = $this->escape;
$sanitize = $this->sanitize;
foreach ($this->filters as $filter) {
$name = $filter->name->name;
if (['nocheck' => 1, 'noCheck' => 1][$name] ?? null) {
$nocheck = true;
$sanitize = false;
} elseif ($name === 'noescape') {
$noescape = true;
$escape = false;
} else {
if (['datastream' => 1, 'dataStream' => 1][$name] ?? null) {
$nocheck = true;
$sanitize = false;
}
$expr = $filter->printSimple($context, $expr);
}
}

$escaper = $context->getEscaper();
if (empty($nocheck)) {
if ($sanitize) {
$expr = $escaper->sanitize($expr);
}

if ($this->escape && empty($noescape)) {
if ($escape) {
$expr = $escaper->escape($expr);
}

Expand Down

0 comments on commit 227d835

Please sign in to comment.