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:
Alan Guo Xiang Tan 2024-02-27 10:18:38 +08:00 committed by GitHub
parent e84d462e28
commit 412b36cc93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -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:,

View File

@ -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:

View 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