Skip to content

Commit 46875ea

Browse files
committed
CsrfProtection: ignores setValue(), is not erased by Form::setValues() [Closes #39][Closes #40]
1 parent 4c885c8 commit 46875ea

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Forms/Controls/CsrfProtection.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ protected function attached($parent)
4242
}
4343

4444

45+
/**
46+
* @return self
47+
*/
48+
public function setValue($value)
49+
{
50+
return $this;
51+
}
52+
53+
54+
/**
55+
* Loads HTTP data.
56+
* @return void
57+
*/
58+
public function loadHttpData()
59+
{
60+
$this->value = $this->getHttpData(Nette\Forms\Form::DATA_TEXT);
61+
}
62+
63+
4564
/**
4665
* @return string
4766
*/

tests/Forms/Controls.CsrfProtection.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Assert::match('<input type="hidden" name="_token_" value="%S%">', (string) $inpu
2727
$input->setValue(NULL);
2828
Assert::false(CsrfProtection::validateCsrf($input));
2929

30-
$input->setValue('12345678901234567890123456789012345678');
30+
call_user_func(array($input, 'Nette\Forms\Controls\BaseControl::setValue'), '12345678901234567890123456789012345678');
3131
Assert::false(CsrfProtection::validateCsrf($input));
3232

3333
$value = $input->getControl()->value;
34-
$input->setValue($value);
34+
call_user_func(array($input, 'Nette\Forms\Controls\BaseControl::setValue'), $value);
3535
Assert::true(CsrfProtection::validateCsrf($input));
3636

3737
session_regenerate_id();
38-
$input->setValue($value);
38+
call_user_func(array($input, 'Nette\Forms\Controls\BaseControl::setValue'), $value);
3939
Assert::false(CsrfProtection::validateCsrf($input));

0 commit comments

Comments
 (0)