FIX: don't allow spaces in 'reply_by_email_address' site setting

This commit is contained in:
Régis Hanol 2018-04-17 17:08:12 +02:00
parent ad4c25e004
commit 2585ada5ca
2 changed files with 10 additions and 4 deletions

View File

@ -4,14 +4,19 @@ class ReplyByEmailAddressValidator
end
def valid_value?(val)
val&.strip!
return true if val.blank?
return false if val["@"].nil?
return false if !val.include?("@")
value = val.dup
if SiteSetting.find_related_post_with_key
!!val["%{reply_key}"] && val.sub(/\+?%{reply_key}/, "") != SiteSetting.notification_email
else
val != SiteSetting.notification_email
return false if !value.include?("%{reply_key}")
value.sub!(/\+?%{reply_key}/, "")
end
value != SiteSetting.notification_email && !value.include?(" ")
end
def error_message

View File

@ -12,6 +12,7 @@ describe ReplyByEmailAddressValidator do
it "returns false if value is not an email address" do
expect(validator.valid_value?('WAT%{reply_key}.com')).to eq(false)
expect(validator.valid_value?('word +%{reply_key}@example.com')).to eq(false)
end
it "returns false if value does not contain '%{reply_key}'" do