From ea562aeadab3f9f58e8db6ee5e86a4a41509db6a Mon Sep 17 00:00:00 2001 From: Paul Hammond Date: Wed, 17 Dec 2014 19:05:39 -0800 Subject: [PATCH] Correctly decode entities from messages --- src/slack.coffee | 3 +++ test/slack.coffee | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/slack.coffee b/src/slack.coffee index 67cacdde..a0cf4604 100644 --- a/src/slack.coffee +++ b/src/slack.coffee @@ -170,6 +170,9 @@ class SlackBot extends Adapter "#{label} (#{link})" else link + text = text.replace /</g, '<' + text = text.replace />/g, '>' + text = text.replace /&/g, '&' text send: (envelope, messages...) -> diff --git a/test/slack.coffee b/test/slack.coffee index 181b4ce3..f8576fc7 100644 --- a/test/slack.coffee +++ b/test/slack.coffee @@ -57,6 +57,10 @@ describe 'Removing message formatting', -> foo = slackbot.removeFormatting 'foo' foo.should.equal 'foo' + it 'Should decode entities', -> + foo = slackbot.removeFormatting 'foo > & < >&<' + foo.should.equal 'foo > & < >&<' + it 'Should change <@U1234> links to @name', -> foo = slackbot.removeFormatting 'foo <@U123> bar' foo.should.equal 'foo @name bar' @@ -105,6 +109,10 @@ describe 'Removing message formatting', -> foo = slackbot.removeFormatting 'foo bar' foo.should.equal 'foo https://www.example.com bar' + it 'Should remove formatting around links with a label containing entitles', -> + foo = slackbot.removeFormatting 'foo bar' + foo.should.equal 'foo label > & < (https://www.example.com) bar' + it 'Should remove formatting around links', -> foo = slackbot.removeFormatting 'foo bar' foo.should.equal 'foo name@example.com bar'