Skip to content

Commit

Permalink
fix: TypeError in form()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 9, 2024
1 parent 4b2175c commit e1cf987
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
{
// If no action is provided then set to the current url
if ($action === '') {
$action = current_url(true);
$action = (string) current_url(true);
} // If an action is not a full URL then turn it into one
elseif (! str_contains($action, '://')) {
// If an action has {locale}
Expand Down
38 changes: 25 additions & 13 deletions tests/system/Helpers/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,33 @@ public function testFormOpenWithoutAction(): void
{
$this->setRequest();

$before = (new Filters())->globals['before'];
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
$Value = csrf_hash();
$Name = csrf_token();
$expected = <<<EOH
<form action="http://example.com/index.php" name="form" id="form" method="POST" accept-charset="utf-8">
<input type="hidden" name="{$Name}" value="{$Value}" style="display:none;">
$expected = <<<'EOH'
<form action="http://example.com/index.php" name="form" id="form" method="POST" accept-charset="utf-8">

EOH;
} else {
$expected = <<<'EOH'
<form action="http://example.com/index.php" name="form" id="form" method="POST" accept-charset="utf-8">
EOH;
$attributes = [
'name' => 'form',
'id' => 'form',
'method' => 'POST',
];
$this->assertSame($expected, form_open('', $attributes));
}

EOH;
}
public function testFormOpenWithoutActionWithCSRF(): void
{
$this->setRequest();

// Sets csrf filter.
$filters = config(Filters::class);
$filters->globals['before'][] = 'csrf';
service('filters')->initialize();

$Value = csrf_hash();
$Name = csrf_token();
$expected = <<<EOH
<form action="http://example.com/index.php" name="form" id="form" method="POST" accept-charset="utf-8">
<input type="hidden" name="{$Name}" value="{$Value}">
EOH;
$attributes = [
'name' => 'form',
'id' => 'form',
Expand Down

0 comments on commit e1cf987

Please sign in to comment.