FIX: Validate email_accent_bg_color color (PR #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.


I think you can reduce the regexp to this

    if (/^#?([0-9a-f]{3}){1,2}$/i.test(color)) {

Ditto, you should be able to reduce the regepx to this (ruby has the nice \h shorthand for hexadecimals

    val =~ /^#(\h{3}){1,2}$/i || COLORS.include?(val&.downcase)

Should we be more descriptive / helpful here? Maybe something like

Invalid color. Either hexadecimal value or a color name.

Any reasons why you’re not using eq(false) or be false?

We’re rather be explicit about when we expect a method to return a boolean.

The site setting description says:

The accent color to be used as the background of some elements in HTML emails. Enter a color name (‘red’) or hex value (’#FF0000’).

I noticed all the error messages are short and cut to the point. Do you still want me to make the error more descriptive?

Yes, we should always strive for better error messages.