Skip to content

Commit

Permalink
fix: escape outgoing messages in listener
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Dec 30, 2018
1 parent 51faabf commit 2c2c2c4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
8 changes: 0 additions & 8 deletions src/entity/Message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as escape from 'escape-html';
import { GraphQLInputObjectType, GraphQLList, GraphQLObjectType, GraphQLString } from 'graphql';
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm';

Expand Down Expand Up @@ -64,13 +63,6 @@ export class Message extends LabelEntity implements MessageOptions {
}
}

/**
* @TODO: move this to each listener
*/
get escaped(): string {
return escape(this.body);
}

public toJSON(): object {
return {
body: this.body,
Expand Down
5 changes: 3 additions & 2 deletions src/listener/DiscordListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TextChannel,
User,
} from 'discord.js';
import * as escape from 'escape-html';
import { isNil } from 'lodash';
import * as emoji from 'node-emoji';
import { Inject } from 'noicejs';
Expand Down Expand Up @@ -113,7 +114,7 @@ export class DiscordListener extends SessionListener<DiscordListenerData> implem
}

if (msg.body.length) {
await thread.reply(msg.body);
await thread.reply(escape(msg.body));
}

const reactions = this.filterEmoji(msg.reactions);
Expand All @@ -137,7 +138,7 @@ export class DiscordListener extends SessionListener<DiscordListenerData> implem
return;
}

await channel.send(msg.body);
await channel.send(escape(msg.body));
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/listener/SlackListener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RTMClient, WebClient } from '@slack/client';
import * as escape from 'escape-html';
import { isNil } from 'lodash';
import { BaseError, Inject, logWithLevel } from 'noicejs';

Expand Down Expand Up @@ -30,7 +31,7 @@ export class SlackListener extends SessionListener<SlackListenerData> implements

public async send(msg: Message): Promise<void> {
if (msg.context.channel.id) {
const result = await this.client.sendMessage(msg.body, msg.context.channel.id);
const result = await this.client.sendMessage(escape(msg.body), msg.context.channel.id);
if (result.error) {
const err = new BaseError(result.error.msg);
this.logger.error(err, 'error sending slack message');
Expand Down

0 comments on commit 2c2c2c4

Please sign in to comment.