Skip to content

Commit a50af96

Browse files
committed
fix: update csrfHard
1 parent 5f0f0e7 commit a50af96

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎src/Blade.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ public function __call(string $method, array $params)
186186
}
187187

188188
/**
189-
* Called when @csrf is rendered without the leafs/csrf module installed.
189+
* Called when @csrfHard is rendered without the leafs/csrf module installed.
190190
* A CSRF directive that silently outputs nothing leaves forms unprotected
191191
* while looking protected, so this fails loudly instead: an exception in
192192
* debug, a logged warning in production.
193193
*/
194194
public static function csrfModuleMissing()
195195
{
196-
$message = '@csrf was rendered but the leafs/csrf module is not installed, so this form is NOT protected. Run `leaf install csrf` or `composer require leafs/csrf`, or remove the @csrf directive.';
196+
$message = '@csrfHard was rendered but the leafs/csrf module is not installed, so this form is NOT protected. Run `leaf install csrf` or `composer require leafs/csrf`, or switch to @csrf if protection should stay optional here.';
197197

198198
$debug = true;
199199

‎tests/blade.test.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@
135135
expect($out)->toContain('public');
136136
});
137137

138-
test('@csrf throws loudly when the csrf module is missing', function () {
139-
template('csrf-missing', '<form>@csrf</form>');
138+
test('@csrf stays silent without the module; @csrfHard fails loudly', function () {
139+
template('csrf-missing', '[@csrf]');
140+
template('csrf-hard-missing', '<form>@csrfHard</form>');
140141

142+
// @csrf is an activation contract: scaffolds carry it, and it renders
143+
// nothing until leafs/csrf is installed. @csrfHard is the strict variant.
141144
// Must run before the module-present test below, which defines a global csrf().
142-
expect(fn () => blade()->render('csrf-missing'))
145+
expect(blade()->render('csrf-missing'))->toBe('[]');
146+
expect(fn () => blade()->render('csrf-hard-missing'))
143147
->toThrow(Exception::class, 'leafs/csrf module is not installed');
144148
});
145149

0 commit comments

Comments
 (0)