Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip tags on my own #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
},
"homepage": "https://github.com/idobata/hubot-idobata",
"dependencies": {
"request": "~2.65",
"pusher-client": "~0.2.1"
"he": "^1.0.0",
"htmlstrip-native": "^0.1.3",
"pusher-client": "~0.2.1",
"request": "~2.65"
},
"devDependencies": {
"coffee-script": "~1.10.0",
Expand Down
14 changes: 9 additions & 5 deletions src/idobata.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Url = require('url')
Util = require('util')

Request = require('request')
Pusher = require('pusher-client')
Hubot = require('hubot')
Package = require('../package')
Request = require('request')
Pusher = require('pusher-client')
Hubot = require('hubot')
HTMLStrip = require('htmlstrip-native')
HE = require('he')
Package = require('../package')

IDOBATA_URL = process.env.HUBOT_IDOBATA_URL || 'https://idobata.io/'
PUSHER_KEY = process.env.HUBOT_IDOBATA_PUSHER_KEY || '44ffe67af1c7035be764'
Expand Down Expand Up @@ -63,7 +65,9 @@ class Idobata extends Hubot.Adapter

return if "bot:#{bot.id}" == identifier

textMessage = new Hubot.TextMessage(user, message.body_plain, message.id)
stripOptions = {compact_whitespace: true, include_attributes: {alt: true}}
bodyPlain = HE.decode(HTMLStrip.html_strip(message.body || '', stripOptions)).trimRight()
textMessage = new Hubot.TextMessage(user, bodyPlain, message.id)
textMessage.data = message

@receive textMessage
Expand Down
4 changes: 2 additions & 2 deletions test/idobata.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe 'hubot-idobata', ->
request = querystring.parse(body)

assert request['message[room_id]'] == '143'
assert request['message[source]'] == 'hi'
assert request['message[source]'] == 'hi ≠ hoi'

do done

Expand Down Expand Up @@ -114,7 +114,7 @@ describe 'hubot-idobata', ->
request = querystring.parse(body)

assert request['message[room_id]'] == '143'
assert request['message[source]'] == '@homuhomu hi'
assert request['message[source]'] == '@homuhomu hi ≠ hoi'

do done

Expand Down
3 changes: 1 addition & 2 deletions test/mock/message.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports =
message:
id: 1535,
body: '<div>hi</div>',
body_plain: 'hi',
body: '<div>hi &ne; hoi</div>',
image_urls: [],
multiline: false,
mentions: [],
Expand Down