mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Validate email_accent_bg_color color (#13778)
Using an invalid value was allowed. This commit tries to automatically fix the color by adding missing # symbol or will show an error to the user if it is not possible and it is not a CSS color either.
This commit is contained in:
39
lib/validators/css_color_validator.rb
Normal file
39
lib/validators/css_color_validator.rb
Normal file
@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CssColorValidator
|
||||
COLORS = %w{
|
||||
aliceblue antiquewhite aqua aquamarine azure beige bisque black
|
||||
blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse
|
||||
chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan
|
||||
darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta
|
||||
darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen
|
||||
darkslateblue darkslategray darkslategrey darkturquoise darkviolet
|
||||
deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite
|
||||
forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green
|
||||
greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender
|
||||
lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan
|
||||
lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon
|
||||
lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue
|
||||
lightyellow lime limegreen linen magenta maroon mediumaquamarine
|
||||
mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue
|
||||
mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream
|
||||
mistyrose moccasin navajowhite navy oldlace olive olivedrab orange
|
||||
orangered orchid palegoldenrod palegreen paleturquoise palevioletred
|
||||
papayawhip peachpuff peru pink plum powderblue purple red rosybrown
|
||||
royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver
|
||||
skyblue slateblue slategray slategrey snow springgreen steelblue tan teal
|
||||
thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen
|
||||
}
|
||||
|
||||
def initialize(opts = {})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(val)
|
||||
!!(val =~ /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/ || COLORS.include?(val&.downcase))
|
||||
end
|
||||
|
||||
def error_message
|
||||
I18n.t("site_settings.errors.invalid_css_color")
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user