From 774edd98f1115808e2aa3820dc57547f8bcded23 Mon Sep 17 00:00:00 2001 From: emerson Date: Wed, 28 Jul 2021 14:28:55 -0400 Subject: [PATCH 1/3] Fix prefix parsing The regex matcher tried to specify specific characters for a nick, which doesn't work anymore. Signed off by Emerson Veenstra --- src/parse_message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse_message.ts b/src/parse_message.ts index 8c730f98..154cec0a 100644 --- a/src/parse_message.ts +++ b/src/parse_message.ts @@ -37,7 +37,7 @@ export function parseMessage(line: string, stripColors: boolean): Message { if (match) { message.prefix = match[1]; line = line.replace(/^:[^ ]+ +/, ''); - match = message.prefix.match(/^([_a-zA-Z0-9\[\]\\`^{}|-]*)(!([^@]+)@(.*))?$/); + match = message.prefix.match(/^([^!]+)(!([^@]+)@(.*))?$/); if (match) { message.nick = match[1]; message.user = match[3]; From 25947e6f9c0e1eb0b972a03fcc34cb6c3a888bca Mon Sep 17 00:00:00 2001 From: emerson Date: Wed, 28 Jul 2021 17:09:02 -0400 Subject: [PATCH 2/3] add test --- test/data/fixtures.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/data/fixtures.json b/test/data/fixtures.json index b6fc871a..1f0d3350 100644 --- a/test/data/fixtures.json +++ b/test/data/fixtures.json @@ -129,8 +129,18 @@ "rawCommand": "324", "commandType": "reply", "args": ["nodebot", "#ubuntu", "+CLcntjf", "5:10", "#ubuntu-unregged"] + }, + ":emerson/matrix!~u@znkrci9cjw8y2.irc PRIVMSG #relaymsg-testing :testing relaymsg2": { + "prefix": "emerson/matrix!~u@znkrci9cjw8y2.irc", + "nick": "emerson/matrix", + "user": "~u", + "host": "znkrci9cjw8y2.irc", + "command": "PRIVMSG", + "rawCommand": "PRIVMSG", + "commandType": "normal", + "args": ["#relaymsg-testing", "testing relaymsg2"], + "stripColors": false } - }, "433-before-001": { "sent": [ From 69bfcd78c81d7a37a3e9348e985c5202c53a7df9 Mon Sep 17 00:00:00 2001 From: emerson Date: Wed, 28 Jul 2021 17:09:45 -0400 Subject: [PATCH 3/3] Make the parser more robust by specifically splitting on ! and @ --- src/parse_message.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/parse_message.ts b/src/parse_message.ts index 154cec0a..87bd0af2 100644 --- a/src/parse_message.ts +++ b/src/parse_message.ts @@ -37,11 +37,18 @@ export function parseMessage(line: string, stripColors: boolean): Message { if (match) { message.prefix = match[1]; line = line.replace(/^:[^ ]+ +/, ''); - match = message.prefix.match(/^([^!]+)(!([^@]+)@(.*))?$/); - if (match) { - message.nick = match[1]; - message.user = match[3]; - message.host = match[4]; + const userDelim = message.prefix.indexOf('!'); + const hostDelim = message.prefix.indexOf('@'); + if (userDelim !== -1 && hostDelim !== -1) { + message.nick = message.prefix.substring(0, userDelim); + message.user = message.prefix.substring(userDelim+1, hostDelim); + message.host = message.prefix.substring(hostDelim+1); + } + else if (userDelim === -1 && hostDelim !== -1) { + // I don't think we'll get here, but we could if someone sends user@server + message.nick = message.prefix.substring(0, hostDelim); + message.user = undefined; + message.host = message.prefix.substring(hostDelim+1); } else { message.server = message.prefix;