Skip to content

Commit bef0521

Browse files
committed
Merge branch 'main' of github.com:panphp/pan
2 parents fb4ecae + bcb08d8 commit bef0521

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Finally, you may start tracking your pages or components adding the `data-pan` a
5757
</div>
5858
```
5959

60+
> [!IMPORTANT]
61+
> Event names must only contain letters, numbers, dashes, and underscores.
62+
6063
## Visualize your product analytics
6164

6265
To visualize your product analytics, you may use the `pan` Artisan command:

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)