From ee9daec36faf5c304ccb80dc31e2e808d73bec4a Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Fri, 15 Apr 2022 10:14:28 -0500 Subject: [PATCH] validate markdown_linkify_tlds setting (#16485) Prevent adding * as a value to markdown_linkify_tlds site setting --- config/locales/server.en.yml | 1 + config/site_settings.yml | 1 + .../markdown_linkify_tlds_validator.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 lib/validators/markdown_linkify_tlds_validator.rb diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 92b0f58b587..dfd396f1ed1 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2404,6 +2404,7 @@ en: leading_trailing_slash: "The regular expression must not start and end with a slash." unicode_usernames_avatars: "The internal system avatars do not support Unicode usernames." list_value_count: "The list must contain exactly %{count} values." + markdown_linkify_tlds: "You cannot include a value of '*'." google_oauth2_hd_groups: "You must first set 'google oauth2 hd' before enabling this setting." search_tokenize_chinese_enabled: "You must disable 'search_tokenize_chinese' before enabling this setting." search_tokenize_japanese_enabled: "You must disable 'search_tokenize_japanese' before enabling this setting." diff --git a/config/site_settings.yml b/config/site_settings.yml index bbfa5ed6408..4e4c836b142 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -847,6 +847,7 @@ posting: type: list default: "com|net|org|io|onion|co|tv|ru|cn|us|uk|me|de|fr|fi|gov" list_type: compact + validator: "MarkdownLinkifyTldsValidator" markdown_typographer_quotation_marks: client: true type: list diff --git a/lib/validators/markdown_linkify_tlds_validator.rb b/lib/validators/markdown_linkify_tlds_validator.rb new file mode 100644 index 00000000000..fbde2026226 --- /dev/null +++ b/lib/validators/markdown_linkify_tlds_validator.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class MarkdownLinkifyTldsValidator + + def initialize(opts = {}) + @opts = opts + end + + def valid_value?(value) + !value.include?("*") + end + + def error_message + I18n.t("site_settings.errors.markdown_linkify_tlds") + end +end