From fecf841aeeaeb46fad594eb4e8f29b64f079978b Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Sat, 29 Aug 2026 13:26:12 +0200 Subject: [PATCH] Require complete hexadecimal color values --- lib/rainbow/color.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rainbow/color.rb b/lib/rainbow/color.rb index 74ec3e3..24d5f3c 100644 --- a/lib/rainbow/color.rb +++ b/lib/rainbow/color.rb @@ -38,12 +38,12 @@ def self.build(ground, values) end def self.parse_hex_color(hex) - unless hex =~ /^#?[a-f0-9]{6}/i + unless hex =~ /\A#?[a-f0-9]{6}\z/i raise ArgumentError, - "Invalid hexadecimal RGB triplet. Valid format: /^#?[a-f0-9]{6}/i" + "Invalid hexadecimal RGB triplet. Expected six hex digits with an optional # prefix" end - hex = hex.sub(/^#/, '') + hex = hex.sub(/\A#/, '') r = hex[0..1].to_i(16) g = hex[2..3].to_i(16) b = hex[4..5].to_i(16)