A platform for community discussion. Free, open, simple.
FIX: `ThemeSettingsObjectValidator` not allowing URL paths for string (#26005)
Alan Guo Xiang Tan955339668bf7
diff --git a/lib/theme_settings_object_validator.rb b/lib/theme_settings_object_validator.rbindex 3939ca18632..9fe134374f2 100644--- a/lib/theme_settings_object_validator.rb+++ b/lib/theme_settings_object_validator.rb@@ -163,7 +163,7 @@ class ThemeSettingsObjectValidatorreturn falseend- if validations&.dig(:url) && !value.match?(URI.regexp)+ if validations&.dig(:url) && !UrlHelper.relaxed_parse(value)add_error(property_name, :string_value_not_valid_url)return falseenddiff --git a/spec/lib/theme_settings_object_validator_spec.rb b/spec/lib/theme_settings_object_validator_spec.rbindex 1f39e099ad7..d575648cf05 100644--- a/spec/lib/theme_settings_object_validator_spec.rb+++ b/spec/lib/theme_settings_object_validator_spec.rb@@ -359,6 +359,38 @@ RSpec.describe ThemeSettingsObjectValidator doexpect(errors["/string_property"].full_messages).to contain_exactly("must be a string")end+ it "should not return an empty hash when string property satsify url validation" do+ schema = {+ name: "section",+ properties: {+ string_property: {+ type: "string",+ validations: {+ url: true,+ },+ },+ },+ }++ expect(+ described_class.new(+ schema: schema,+ object: {+ string_property: "https://www.example.com",+ },+ ).validate,+ ).to eq({})++ expect(+ described_class.new(+ schema: schema,+ object: {+ string_property: "/some-path/to/some-where",+ },+ ).validate,+ ).to eq({})+ end+it "should return the right hash of error messages when string property does not statisfy url validation" doschema = {name: "section",