fix: enhance tag update validation and processing for improved reliability
This commit is contained in:
@@ -69,31 +69,35 @@ class ServerTagController
|
||||
*/
|
||||
public function update(Request $request, $serverId)
|
||||
{
|
||||
$request->validate([
|
||||
'tags' => 'nullable|array|max:3',
|
||||
'tags.*.text' => 'required|string|max:32|regex:/^[a-zA-Z0-9_-]+$/',
|
||||
'tags.*.color' => 'nullable|string|max:16',
|
||||
]);
|
||||
|
||||
$server = Server::where('id', $serverId)
|
||||
->where('user_id', Auth::id())
|
||||
->firstOrFail();
|
||||
|
||||
$tags = $request->input('tags', []);
|
||||
|
||||
// Ensure tags is an array
|
||||
if (!is_array($tags)) {
|
||||
$tags = [];
|
||||
}
|
||||
|
||||
// Limit to 3 tags
|
||||
$tags = array_slice($tags, 0, 3);
|
||||
|
||||
// Process tags and auto-generate colors if not provided
|
||||
$processedTags = [];
|
||||
foreach ($tags as $tag) {
|
||||
$text = trim($tag['text']);
|
||||
if (!is_array($tag) || !isset($tag['text'])) continue;
|
||||
|
||||
$text = trim($tag['text'] ?? '');
|
||||
if (empty($text)) continue;
|
||||
|
||||
// Convert to lowercase and sanitize (Proxmox requires this)
|
||||
$text = strtolower(preg_replace('/[^a-zA-Z0-9_-]/', '', $text));
|
||||
if (empty($text)) continue;
|
||||
|
||||
// Limit tag length to 32 chars
|
||||
$text = substr($text, 0, 32);
|
||||
|
||||
$processedTags[] = [
|
||||
'text' => $text,
|
||||
'color' => $tag['color'] ?? self::generateTagColor($text),
|
||||
|
||||
Reference in New Issue
Block a user