Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/tg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ var logger = require('winston');

var myUser = {};

function irc_to_html_format(text) {
text = text.replace(/\x02(.*?)\x02/g, '<b>$1</b>');
text = text.replace(/\x02(.*)/g, '<b>$1</b>');
text = text.replace(/\x1D(.*?)\x1D/g, '<i>$1</i>');
text = text.replace(/\x1D(.*)/g, '<i>$1</i>');
return text;
}

var init = function(msgCallback) {
// start HTTP server for media files if configured to do so
if (config.showMedia) {
Expand Down Expand Up @@ -64,11 +72,11 @@ var init = function(msgCallback) {
}

if (message.user) {
message.text = '<' + message.user + '> ' + message.text;
message.text = '<' + message.user + '> ' + irc_to_html_format(message.text);
Copy link
Copy Markdown

@melamity melamity Jun 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely if you're sending HTML tags in a message you'd want to escape where it shows the username of the person who talked? It might be mistaken as a tag.

Copy link
Copy Markdown

@omnidan omnidan Jun 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<username> will be interpreted as an XML tag and probably will end up being removed by telegram, same goes for user input that contains these characters. We need to escape all occurences of < and > first.

}

logger.verbose('>> relaying to TG:', message.text);
tg.sendMessage(message.channel.tgChatId, message.text);
tg.sendMessage(message.channel.tgChatId, message.text, parse_mode=telegram.ParseMode.HTML);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax does not exist in JavaScript

}
};
};
Expand Down