mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 09:48:18 +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:
23
spec/components/validators/css_color_validator_spec.rb
Normal file
23
spec/components/validators/css_color_validator_spec.rb
Normal file
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe CssColorValidator do
|
||||
subject { described_class.new }
|
||||
|
||||
it "validates hex colors" do
|
||||
expect(subject.valid_value?('#0')).to eq(false)
|
||||
expect(subject.valid_value?('#00')).to eq(false)
|
||||
expect(subject.valid_value?('#000')).to eq(true)
|
||||
expect(subject.valid_value?('#0000')).to eq(false)
|
||||
expect(subject.valid_value?('#00000')).to eq(false)
|
||||
expect(subject.valid_value?('#000000')).to eq(true)
|
||||
end
|
||||
|
||||
it "validates css colors" do
|
||||
expect(subject.valid_value?('red')).to eq(true)
|
||||
expect(subject.valid_value?('green')).to eq(true)
|
||||
expect(subject.valid_value?('blue')).to eq(true)
|
||||
expect(subject.valid_value?('hello')).to eq(false)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user