- def email_links(_key, value)
- # Does value look like an email? eg "someone@domain.tld"
- # or a list of alternate emails separated by ;
-
- # Uses WHATWG implementation of email validation, which follows RFC 1123
- # but is a willful violation of RFC 5322.
- # (see: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address)
- if value.match?(%r{^\s*[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+
- @[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\s*
- (;\s*[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+
- @[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\s*)*$
- }x)
- return value.split(";").map do |email|
- # remove any leading or trailing whitespace if present
- email = email.strip
-
- # add 'mailto:'' prefix
- { :email => email, :url => "mailto:#{email}" }
- end
- end
+ def email_link(key, value)
+ # Avoid converting conditional tags into emails, since EMAIL_REGEXP is quite permissive
+ return nil unless %w[email contact:email].include? key
+
+ # Does the value look like an email? eg "someone@domain.tld"
+
+ # Uses Ruby built-in regexp to validate email.
+ # This will not catch certain valid emails containing comments, whitespace characters,
+ # and quoted strings.
+ # (see: https://github.com/ruby/ruby/blob/master/lib/uri/mailto.rb)
+
+ # remove any leading and trailing whitespace
+ email = value.strip
+
+ return email if email.match?(URI::MailTo::EMAIL_REGEXP)
+