diff --git a/lib/rainbow/color.rb b/lib/rainbow/color.rb index 4140c0c..8ce5785 100644 --- a/lib/rainbow/color.rb +++ b/lib/rainbow/color.rb @@ -36,6 +36,11 @@ def self.build(ground, values) end def self.parse_hex_color(hex) + unless hex =~ /^#?[a-f0-9]{6}/i + raise ArgumentError, + "Invalid hexadecimal RGB triplet. Valid format: /^#?[a-f0-9]{6}/i" + end + hex = hex.sub(/^#/, '') r = hex[0..1].to_i(16) g = hex[2..3].to_i(16)