Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/3805'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Nov 17, 2022
2 parents 14e73fd + 97b7bac commit 17e87ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
7 changes: 2 additions & 5 deletions app/helpers/browse_tags_helper.rb
Expand Up @@ -22,7 +22,7 @@ def format_value(key, value)
elsif url = wiki_link("tag", "#{key}=#{value}")
link_to h(value), url, :title => t("browse.tag_details.wiki_link.tag", :key => key, :value => value)
elsif email = email_link(key, value)
link_to(h(email[:email]), email[:url], :title => t("browse.tag_details.email_link", :email => email[:email]))
mail_to(email, :title => t("browse.tag_details.email_link", :email => email))
elsif phones = telephone_links(key, value)
# similarly, telephone_links() returns an array of phone numbers
phones = phones.map do |p|
Expand Down Expand Up @@ -136,10 +136,7 @@ def email_link(_key, value)
# remove any leading and trailing whitespace
email = value.strip

if email.match?(URI::MailTo::EMAIL_REGEXP)
# add 'mailto:'' prefix
return { :email => email, :url => "mailto:#{email}" }
end
return email if email.match?(URI::MailTo::EMAIL_REGEXP)

nil
end
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -405,6 +405,7 @@ en:
wikimedia_commons_link: "The %{page} item on Wikimedia Commons"
telephone_link: "Call %{phone_number}"
colour_preview: "Colour %{colour_value} preview"
email_link: "Email %{email}"
note:
title: "Note: %{id}"
new_note: "New Note"
Expand Down
21 changes: 9 additions & 12 deletions test/helpers/browse_tags_helper_test.rb
Expand Up @@ -46,6 +46,9 @@ def test_format_value

html = format_value("colour", "#f00")
assert_dom_equal %(<span class="colour-preview-box" data-colour="#f00" title="Colour #f00 preview"></span>#f00), html

html = format_value("contact", "foo@example.com")
assert_dom_equal "<a title=\"Email foo@example.com\" href=\"mailto:foo@example.com\">foo@example.com</a>", html
end

def test_wiki_link
Expand Down Expand Up @@ -240,29 +243,23 @@ def test_email_link
assert_nil email

email = email_link("email", "x@example.com")
assert_equal "x@example.com", email[:email]
assert_equal "mailto:x@example.com", email[:url]
assert_equal "x@example.com", email

email = email_link("email", "other.email-with-hyphen@example.com")
assert_equal "other.email-with-hyphen@example.com", email[:email]
assert_equal "mailto:other.email-with-hyphen@example.com", email[:url]
assert_equal "other.email-with-hyphen@example.com", email

email = email_link("email", "user.name+tag+sorting@example.com")
assert_equal "user.name+tag+sorting@example.com", email[:email]
assert_equal "mailto:user.name+tag+sorting@example.com", email[:url]
assert_equal "user.name+tag+sorting@example.com", email

email = email_link("email", "dash-in@both-parts.com")
assert_equal "dash-in@both-parts.com", email[:email]
assert_equal "mailto:dash-in@both-parts.com", email[:url]
assert_equal "dash-in@both-parts.com", email

email = email_link("email", "example@s.example")
assert_equal "example@s.example", email[:email]
assert_equal "mailto:example@s.example", email[:url]
assert_equal "example@s.example", email

# Strips whitespace at ends
email = email_link("email", " test@email.com ")
assert_equal "test@email.com", email[:email]
assert_equal "mailto:test@email.com", email[:url]
assert_equal "test@email.com", email
end

def test_telephone_links
Expand Down

0 comments on commit 17e87ab

Please sign in to comment.