Skip to content

Commit

Permalink
Correctly decode entities from messages
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhammond committed Dec 18, 2014
1 parent a01dbc0 commit ea562ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ class SlackBot extends Adapter
"#{label} (#{link})"
else
link
text = text.replace /&lt;/g, '<'
text = text.replace /&gt;/g, '>'
text = text.replace /&amp;/g, '&'
text

send: (envelope, messages...) ->
Expand Down
8 changes: 8 additions & 0 deletions test/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ describe 'Removing message formatting', ->
foo = slackbot.removeFormatting 'foo'
foo.should.equal 'foo'

it 'Should decode entities', ->
foo = slackbot.removeFormatting 'foo &gt; &amp; &lt; &gt;&amp;&lt;'
foo.should.equal 'foo > & < >&<'

it 'Should change <@U1234> links to @name', ->
foo = slackbot.removeFormatting 'foo <@U123> bar'
foo.should.equal 'foo @name bar'
Expand Down Expand Up @@ -105,6 +109,10 @@ describe 'Removing message formatting', ->
foo = slackbot.removeFormatting 'foo <https://www.example.com|example.com> bar'
foo.should.equal 'foo https://www.example.com bar'

it 'Should remove formatting around <https> links with a label containing entitles', ->
foo = slackbot.removeFormatting 'foo <https://www.example.com|label &gt; &amp; &lt;> bar'
foo.should.equal 'foo label > & < (https://www.example.com) bar'

it 'Should remove formatting around <mailto> links', ->
foo = slackbot.removeFormatting 'foo <mailto:name@example.com> bar'
foo.should.equal 'foo name@example.com bar'
Expand Down

0 comments on commit ea562ae

Please sign in to comment.