Skip to content

Commit bcb08d8

Browse files
authored
Merge pull request #28 from austincarpenter/use-alpha-dash-validation-rule
Replace `regex` rule with `alpha_dash:ascii`
2 parents 1bd758d + 2090b57 commit bcb08d8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Adapters/Laravel/Http/Requests/CreateEventRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function rules(): array
2222
{
2323
return [
2424
'events' => ['required', 'array'],
25-
'events.*.name' => ['required', 'string', 'regex:/^[A-Za-z0-9-_]+$/'],
25+
'events.*.name' => ['required', 'string', 'alpha_dash:ascii'],
2626
'events.*.type' => ['required', Rule::enum(EventType::class)],
2727
];
2828
}

tests/Feature/Laravel/Http/EventsTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@
7979
]);
8080
});
8181

82+
it('does not create an analytic event if the event name is invalid', function (string $name): void {
83+
$response = $this->post('/pan/events', [
84+
'events' => [[
85+
'name' => $name,
86+
'type' => 'impression',
87+
]],
88+
]);
89+
90+
$response->assertStatus(302)->assertSessionHasErrors([
91+
'events.0.name' => 'The events.0.name field must only contain letters, numbers, dashes, and underscores.',
92+
]);
93+
94+
$analytics = array_map(fn (Analytic $analytic): array => $analytic->toArray(), app(AnalyticsRepository::class)->all());
95+
96+
expect($analytics)->toBe([]);
97+
})->with([
98+
'help modal',
99+
'help.modal',
100+
'help/modal',
101+
'🙋',
102+
]);
103+
82104
it('does not create an analytic event if the event is invalid', function (): void {
83105
$response = $this->post('/pan/events', [
84106
'events' => [[

0 commit comments

Comments
 (0)