Skip to content
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

Attempt to solve mixing GET & POST params in AJAX without BC break #127

Merged
merged 1 commit into from
Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Application/UI/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function attached($presenter)
$this->setAction(new Link($presenter, 'this', []));
$signal = new Nette\Forms\Controls\HiddenField($name . self::NAME_SEPARATOR . 'submit');
$signal->setOmitted()->setHtmlId(FALSE);
$this[Presenter::SIGNAL_KEY] = $signal;
$this['_' . Presenter::SIGNAL_KEY . '_'] = $signal;
}
}
parent::attached($presenter);
Expand Down
10 changes: 6 additions & 4 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1219,11 +1219,13 @@ private function initGlobalParameters()
$selfParams = [];

$params = $this->request->getParameters();
if ($this->isAjax()) {
$params += $this->request->getPost();
}
if (($tmp = $this->request->getPost(self::SIGNAL_KEY)) !== NULL) {
if (($tmp = $this->request->getPost('_' . self::SIGNAL_KEY . '_')) !== NULL) {
$params[self::SIGNAL_KEY] = $tmp;
} elseif ($this->isAjax()) {
$params += $this->request->getPost();
if (($tmp = $this->request->getPost(self::SIGNAL_KEY)) !== NULL) {
$params[self::SIGNAL_KEY] = $tmp;
}
}

foreach ($params as $key => $value) {
Expand Down
34 changes: 31 additions & 3 deletions tests/UI/Presenter.parameters.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,33 @@ test(function () {
$presenter->run(new Application\Request('Foo', 'POST', [], [
'do' => 'foo'
]));
Assert::null($presenter->getSignal());
});

test(function () {
//_signal_ in POST
$presenter = createPresenter();
$presenter->run(new Application\Request('Foo', 'POST', [], [
'_do_' => 'foo'
]));
Assert::same(['', 'foo'], $presenter->getSignal());
});

test(function () {
//signal in POST overwriting empty GET
//signal in POST not overwriting GET
$presenter = createPresenter();
$presenter->run(new Application\Request('Foo', 'POST', ['do' => NULL], [
'do' => 'foo'
]));
Assert::null($presenter->getSignal());
});

test(function () {
//_signal_ in POST overwriting GET
$presenter = createPresenter();
$presenter->run(new Application\Request('Foo', 'POST', ['do' => 'bar'], [
'_do_' => 'foo'
]));
Assert::same(['', 'foo'], $presenter->getSignal());
});

Expand All @@ -89,11 +107,21 @@ test(function () {
});

test(function () {
//AJAX: signal in POST overwriting empty GET
//AJAX: signal in POST overwriting GET
$presenter = createPresenter();
$presenter->ajax = TRUE;
$presenter->run(new Application\Request('Foo', 'POST', ['do' => NULL], [
$presenter->run(new Application\Request('Foo', 'POST', ['do' => 'bar'], [
'do' => 'foo'
]));
Assert::same(['', 'foo'], $presenter->getSignal());
});

test(function () {
//AJAX: _signal_ in POST overwriting GET
$presenter = createPresenter();
$presenter->ajax = TRUE;
$presenter->run(new Application\Request('Foo', 'POST', ['do' => 'bar'], [
'_do_' => 'foo'
]));
Assert::same(['', 'foo'], $presenter->getSignal());
});