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