Skip to content

Commit

Permalink
Fix _COOKIE conditions (#2809)
Browse files Browse the repository at this point in the history
Resolves: #2805
  • Loading branch information
sabbelasichon authored Jan 27, 2022
1 parent 22b21ea commit 9c08a83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function change(string $condition): ?string
$newConditions = [];
foreach ($subConditions as $subCondition) {
preg_match(
'#(?<type>ENV|IENV|GP|TSFE|LIT)' . self::ZERO_ONE_OR_MORE_WHITESPACES . ':' . self::ZERO_ONE_OR_MORE_WHITESPACES . '(?<property>.*)\s*(?<operator>' . self::ALLOWED_OPERATORS_REGEX . ')' . self::ZERO_ONE_OR_MORE_WHITESPACES . '(?<value>.*)$#Ui',
'#(?<type>ENV|IENV|GP|TSFE|LIT|_COOKIE)' . self::ZERO_ONE_OR_MORE_WHITESPACES . '[:|]' . self::ZERO_ONE_OR_MORE_WHITESPACES . '(?<property>.*)\s*(?<operator>' . self::ALLOWED_OPERATORS_REGEX . ')' . self::ZERO_ONE_OR_MORE_WHITESPACES . '(?<value>.*)$#Ui',
$subCondition,
$matches
);
Expand All @@ -44,6 +44,7 @@ public function change(string $condition): ?string
'IENV' => $this->createIndependentCondition($property, $operator, $value),
'TSFE' => $this->refactorTsfe($property, $operator, $value),
'GP' => $this->refactorGetPost($property, $operator, $value),
'_COOKIE' => $this->refactorCookie($property, $operator, $value),
'LIT' => sprintf('"%s" %s "%s"', $value, self::OPERATOR_MAPPING[$operator], $property),
default => '',
};
Expand Down Expand Up @@ -85,4 +86,14 @@ private function refactorGetPost(string $property, string $operator, string $val
$value
);
}

private function refactorCookie(string $property, string $operator, string $value): string
{
return sprintf(
'request.getCookieParams()[\'%1$s\'] %3$s \'%2$s\'',
$property,
$value,
self::OPERATOR_MAPPING[$operator]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ public function statements(): Iterator
'oldCondition' => '[globalVar = _POST:tx_powermail_pi1|action = create]',
'newCondition' => "[traverse(request.getParsedBody(), 'tx_powermail_pi1/action') == 'create')]",
];

yield '_COOKIE' => [
'oldCondition' => '[globalString = _COOKIE|cookiePolicy=isSet]',
'newCondition' => "[request.getCookieParams()['cookiePolicy'] == 'isSet']",
];
}

/**
Expand Down

0 comments on commit 9c08a83

Please sign in to comment.