Skip to content

Commit

Permalink
DefaultFormRenderer: strict type fix (#220)
Browse files Browse the repository at this point in the history
fixes "TypeError: preg_split() expects parameter 2 to be string, null given" for GET form if action does not contain query parameters
  • Loading branch information
rydercz authored and dg committed Jul 8, 2019
1 parent f0aa853 commit 00a923b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Forms/Rendering/DefaultFormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function renderBegin(): string

if ($this->form->isMethod('get')) {
$el = clone $this->form->getElementPrototype();
$query = parse_url($el->action, PHP_URL_QUERY);
$query = parse_url($el->action, PHP_URL_QUERY) ?: '';
$el->action = str_replace("?$query", '', $el->action);
$s = '';
foreach (preg_split('#[;&]#', $query, -1, PREG_SPLIT_NO_EMPTY) as $param) {
Expand Down
43 changes: 43 additions & 0 deletions tests/Forms/Forms.renderer.6.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Test: Nette\Forms default rendering GET form.
*/

declare(strict_types=1);

use Tester\Assert;

require __DIR__ . '/../bootstrap.php';


$form = new Nette\Forms\Form;
$form->setMethod('GET');
$form->setAction('link');
$form->addCheckboxList('list')
->setItems(['First', 'Second']);
$form->addHidden('userid');
$form->addSubmit('submit', 'Send');

$form->fireEvents();

Assert::match('<form action="link" method="get">
<table>
<tr>
<th><label></label></th>
<td><label><input type="checkbox" name="list[]" value="0">First</label><br><label><input type="checkbox" name="list[]" value="1">Second</label></td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="_submit" value="Send" class="button"></td>
</tr>
</table>
<input type="hidden" name="userid" value=""><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->
</form>', $form->__toString(true));

Assert::same('link', $form->getAction());

0 comments on commit 00a923b

Please sign in to comment.