Skip to content

Commit

Permalink
Support multiple email addresses in mailto
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Apr 18, 2023
1 parent bcc4bac commit 0e3d881
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/html_proofer/check/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def handle_mailto
"#{@link.url.raw_attribute} contains no email address",
element: @link,
) unless ignore_empty_mailto?
elsif !/#{URI::MailTo::EMAIL_REGEXP}/o.match?(@link.url.path)
# eg., if any do not match a valid URL
elsif @link.url.path.split(",").any? { |email| !/#{URI::MailTo::EMAIL_REGEXP}/o.match?(email) }
add_failure(
"#{@link.url.raw_attribute} contains an invalid email address",
element: @link,
Expand Down
5 changes: 5 additions & 0 deletions spec/html-proofer/fixtures/links/multiple_mailto_links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<a href="mailto:[email protected],[email protected],[email protected]">Mail me</a>.
</body>
</html>
6 changes: 6 additions & 0 deletions spec/html-proofer/links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@
expect(proofer.failed_checks).to(eq([]))
end

it "accepts multiple mailto links" do
ignorable_links = File.join(FIXTURES_DIR, "links", "multiple_mailto_links.html")
proofer = run_proofer(ignorable_links, :file)
expect(proofer.failed_checks).to(eq([]))
end

it "ignores blank mailto links when configured to allow them" do
blank_mail_to_link = File.join(FIXTURES_DIR, "links", "blank_mailto_link.html")
proofer = run_proofer(blank_mail_to_link, :file, ignore_empty_mailto: true)
Expand Down

0 comments on commit 0e3d881

Please sign in to comment.