From 6a78669ca3ccf694517a4e910f69bc4134267f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 2 Mar 2018 17:53:18 +0100 Subject: [PATCH] FIX: 'reply by email addresses' site settings should allow email addresses without a 'reply_key' when 'find related post with key' is disabled --- config/site_settings.yml | 1 + lib/validators/reply_by_email_address_validator.rb | 11 +++++++---- .../reply_by_email_address_validator_spec.rb | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config/site_settings.yml b/config/site_settings.yml index 547f7654c42..1f6c8f0a9f7 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -705,6 +705,7 @@ email: validator: "ReplyByEmailEnabledValidator" reply_by_email_address: default: '' + validator: "ReplyByEmailAddressValidator" alternative_reply_by_email_addresses: default: '' validator: "AlternativeReplyByEmailAddressesValidator" diff --git a/lib/validators/reply_by_email_address_validator.rb b/lib/validators/reply_by_email_address_validator.rb index 3c3b5698f89..ff668bf8582 100644 --- a/lib/validators/reply_by_email_address_validator.rb +++ b/lib/validators/reply_by_email_address_validator.rb @@ -4,11 +4,14 @@ class ReplyByEmailAddressValidator end def valid_value?(val) - return true if val.blank? + return true if val.blank? + return false if val["@"].nil? - !!val["@"] && - !!val["%{reply_key}"] && - val.gsub(/\+?%{reply_key}/, "") != SiteSetting.notification_email + if SiteSetting.find_related_post_with_key + !!val["%{reply_key}"] && val.sub(/\+?%{reply_key}/, "") != SiteSetting.notification_email + else + val != SiteSetting.notification_email + end end def error_message diff --git a/spec/components/validators/reply_by_email_address_validator_spec.rb b/spec/components/validators/reply_by_email_address_validator_spec.rb index ac580b7f016..cf7a889a4a7 100644 --- a/spec/components/validators/reply_by_email_address_validator_spec.rb +++ b/spec/components/validators/reply_by_email_address_validator_spec.rb @@ -18,6 +18,11 @@ describe ReplyByEmailAddressValidator do expect(validator.valid_value?('foo@bar.com')).to eq(false) end + it "returns true if value does not contain '%{reply_key}' but 'find_related_post_with_key' is also disabled" do + SiteSetting.expects(:find_related_post_with_key).returns(false) + expect(validator.valid_value?('foo@bar.com')).to eq(true) + end + it "returns false if value is the same as SiteSetting.notification_email" do SiteSetting.expects(:notification_email).returns("foo@bar.com") expect(validator.valid_value?('foo+%{reply_key}@bar.com')).to eq(false)