mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Add experimental json_scheme site setting type (#12226)
This commit is contained in:
@ -17,9 +17,23 @@ class StringSettingValidator
|
||||
return false
|
||||
end
|
||||
|
||||
return valid_json?(val) if (@opts[:json_schema])
|
||||
|
||||
regex_match?(val)
|
||||
end
|
||||
|
||||
def valid_json?(json)
|
||||
# TODO: right now this is only ensuring JSON is valid
|
||||
# but ideally we should validate against the schema
|
||||
begin
|
||||
JSON.parse(json)
|
||||
rescue JSON::ParserError => e
|
||||
@json_fail = true
|
||||
return false
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def error_message
|
||||
if @regex_fail
|
||||
I18n.t(@regex_error)
|
||||
@ -31,6 +45,8 @@ class StringSettingValidator
|
||||
else
|
||||
I18n.t('site_settings.errors.invalid_string_max', max: @opts[:max])
|
||||
end
|
||||
elsif @json_fail
|
||||
I18n.t('site_settings.errors.invalid_json')
|
||||
else
|
||||
I18n.t('site_settings.errors.invalid_string')
|
||||
end
|
||||
|
Reference in New Issue
Block a user