Skip to content

Commit 175f2b8

Browse files
committed
Fixed problems with the inability to locally disable antiForgeryToken.
Added support for arrays in the function actionNameEquals() and controllerNameEquals().
1 parent 3ed8e1c commit 175f2b8

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

src/ActionContext.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,25 @@ public function getActionName() {
176176
/**
177177
* Checks the equivalence of the specified string with the name of the action.
178178
*
179-
* @param string $name The string to compare.
179+
* @param string|array $name The string or string array to compare.
180180
*
181181
* @return bool
182182
*/
183183
public function actionNameEquals($name) {
184-
return strtolower($this->actionName) == strtolower($name);
184+
$actionName = strtolower($this->actionName);
185+
186+
if (is_array($name)) {
187+
foreach ($name as $n) {
188+
if ($actionName == strtolower($n)) {
189+
return true;
190+
}
191+
}
192+
193+
return false;
194+
}
195+
else {
196+
return $actionName == strtolower($name);
197+
}
185198
}
186199

187200
/**
@@ -196,12 +209,25 @@ public function getControllerName() {
196209
/**
197210
* Checks the equivalence of the specified string with the name of the controller.
198211
*
199-
* @param string $name The string to compare.
212+
* @param string|array $name The string or string array to compare.
200213
*
201214
* @return bool
202215
*/
203216
public function controllerNameEquals($name) {
204-
return strtolower($this->getControllerName()) == strtolower($name);
217+
$controllerName = strtolower($this->getControllerName());
218+
219+
if (is_array($name)) {
220+
foreach ($name as $n) {
221+
if ($controllerName == strtolower($n)) {
222+
return true;
223+
}
224+
}
225+
226+
return false;
227+
}
228+
else {
229+
return $controllerName == strtolower($name);
230+
}
205231
}
206232

207233
/**

src/AppBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,11 @@ private static function validation() {
890890

891891
if (!isset($post)) { $post = array(); }
892892

893-
if ((isset($expected) && (!isset($post['__requestVerificationToken']) || $post['__requestVerificationToken'] != $expected)) || (isset($post['__requestVerificationToken']) && empty($expected))) {
893+
if (
894+
(isset($expected) && $expected !== 'false' && (!isset($post['__requestVerificationToken']) || $post['__requestVerificationToken'] != $expected)) ||
895+
(isset($expected) && $expected === 'false' && !empty($post['__requestVerificationToken'])) ||
896+
(isset($post['__requestVerificationToken']) && empty($expected))
897+
) {
894898
throw new HttpAntiForgeryException();
895899
}
896900
}

src/Html.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ public static function beginForm($actionName, $controllerName = null, $routeValu
343343
elseif (is_array($antiforgery)) {
344344
$result .= self::antiForgeryToken(true);
345345
}
346+
else {
347+
self::$viewContext->getHttpContext()->getResponse()->addCookie('__requestVerificationToken', 'false', 0, '/', '', false, true);
348+
}
346349

347350
return $result;
348351
}

src/Info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
*/
3131
final class Info {
3232

33-
const VERSION = '1.1.0';
33+
const VERSION = '1.1.1';
3434

3535
}

0 commit comments

Comments
 (0)