mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:49:06 +08:00
FIX: Error when integer values are set as default of string type settings (#25898)
Why this change? ``` some_setting: default: 0 type: string ``` A theme setting like the above will cause an error to be thrown on the server when importing the theme because the default would be parsed as an integer which caused an error to be thrown when we are validating the value of the setting. What does this change do? Convert the value to a string when working with string typed theme settings.
This commit is contained in:
parent
e84d462e28
commit
412b36cc93
|
@ -45,7 +45,7 @@ class ThemeSettingsValidator
|
|||
)
|
||||
when types[:string]
|
||||
validate_value_in_range!(
|
||||
value.length,
|
||||
value.to_s.length,
|
||||
min: opts[:min],
|
||||
max: opts[:max],
|
||||
errors:,
|
||||
|
|
|
@ -14,6 +14,10 @@ string_setting_03:
|
|||
default: "string value"
|
||||
textarea: true
|
||||
|
||||
string_setting_04:
|
||||
default: 0
|
||||
type: string
|
||||
|
||||
integer_setting: 51
|
||||
|
||||
integer_setting_02:
|
||||
|
|
11
spec/lib/theme_settings_validator_spec.rb
Normal file
11
spec/lib/theme_settings_validator_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe ThemeSettingsValidator do
|
||||
describe ".validate_value" do
|
||||
it "does not throw an error when an integer value is given with type `string`" do
|
||||
errors = described_class.validate_value(1, ThemeSetting.types[:string], {})
|
||||
|
||||
expect(errors).to eq([])
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user