fix: add hex color validation to Category model and form (to solve #1247) (#1341)

- Added server-side validation to Category model to enforce 6-digit hex format for colors.
- Added HTML pattern attribute to category form for client-side validation.
- Updated tests to cover validation and fixed existing tests using shorthand hex colors.
This commit is contained in:
Louis
2026-04-01 20:27:29 +02:00
committed by GitHub
parent a90f9b7317
commit 8ed69132cf
4 changed files with 19 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ class Category < ApplicationRecord
belongs_to :parent, class_name: "Category", optional: true
validates :name, :color, :lucide_icon, :family, presence: true
validates :color, format: { with: /\A#[0-9A-Fa-f]{6}\z/ }
validates :name, uniqueness: { scope: :family_id }
validate :category_level_limit