From 79413e7c45216ff37f5d8a59206f054ce7c84b16 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 25 Nov 2015 18:29:59 -0800 Subject: [PATCH] fix(autolinker): Add title attr to all links in emails to display href Fixes GitHub Issues #479 and #335 --- .../lib/plugins/autolinker-extension.coffee | 6 ++++ .../spec/autolinker-extension-spec.coffee | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 internal_packages/message-list/spec/autolinker-extension-spec.coffee diff --git a/internal_packages/message-list/lib/plugins/autolinker-extension.coffee b/internal_packages/message-list/lib/plugins/autolinker-extension.coffee index 358dc0949..6c2f5060d 100644 --- a/internal_packages/message-list/lib/plugins/autolinker-extension.coffee +++ b/internal_packages/message-list/lib/plugins/autolinker-extension.coffee @@ -7,4 +7,10 @@ class AutolinkerExtension extends MessageStoreExtension # Apply the autolinker pass to make emails and links clickable message.body = Autolinker.link(message.body, {twitter: false}) + # Ensure that the hrefs in the email always have alt text so you can't hide + # the target of links + # https://regex101.com/r/cH0qM7/1 + message.body = message.body.replace /href[ ]*=[ ]*?['"]([^'"]*)(['"]+)/gi, (match, url, quoteCharacter) => + return "#{match} title=#{quoteCharacter}#{url}#{quoteCharacter} " + module.exports = AutolinkerExtension diff --git a/internal_packages/message-list/spec/autolinker-extension-spec.coffee b/internal_packages/message-list/spec/autolinker-extension-spec.coffee new file mode 100644 index 000000000..f4202aa16 --- /dev/null +++ b/internal_packages/message-list/spec/autolinker-extension-spec.coffee @@ -0,0 +1,28 @@ +Autolinker = require 'autolinker' +AutolinkerExtension = require '../lib/plugins/autolinker-extension' + +describe "AutolinkerExtension", -> + beforeEach -> + spyOn(Autolinker, 'link').andCallFake (txt) => txt + + it "should call through to Autolinker", -> + AutolinkerExtension.formatMessageBody({body:'body'}) + expect(Autolinker.link).toHaveBeenCalledWith('body', {twitter: false}) + + it "should add a title to everything with an href", -> + message = + body: """ + hello world! + hello world! + hello world! + hello world! + """ + expected = + body: """ + hello world! + hello world! + hello world! + hello world! + """ + AutolinkerExtension.formatMessageBody(message) + expect(message.body).toEqual(expected.body)