Skip to content

Commit 964ddd4

Browse files
committed
Fix task name sanitization
1 parent f356dc2 commit 964ddd4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/CloudTasksQueue.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private function withUuid(array $payload): array
192192

193193
private function taskName(string $queueName, array $payload): string
194194
{
195-
$displayName = str_replace("\\", '-', $payload['displayName']);
195+
$displayName = $this->sanitizeTaskName($payload['displayName']);
196196

197197
return CloudTasksClient::taskName(
198198
$this->config['project'],
@@ -202,6 +202,17 @@ private function taskName(string $queueName, array $payload): string
202202
);
203203
}
204204

205+
private function sanitizeTaskName(string $taskName)
206+
{
207+
// Remove all characters that are not -, letters, numbers, or whitespace
208+
$sanitizedName = preg_replace('![^-\pL\pN\s]+!u', '-', $taskName);
209+
210+
// Replace all separator characters and whitespace by a -
211+
$sanitizedName = preg_replace('![-\s]+!u', '-', $sanitizedName);
212+
213+
return trim($sanitizedName, '-');
214+
}
215+
205216
private function withAttempts(array $payload): array
206217
{
207218
if (!isset($payload['internal']['attempts'])) {

0 commit comments

Comments
 (0)