diff --git a/lib/slack/command.js b/lib/slack/command.js index 576677227..902107ae6 100644 --- a/lib/slack/command.js +++ b/lib/slack/command.js @@ -3,11 +3,22 @@ const { parseSubscriptionArgString } = require('../settings-helper'); const SUBCOMMAND = /^(\w+) *(.*)$/; +function normalizeQuotes(text) { + return text + .replace(/\u00AB/g, '"') + .replace(/\u00BB/g, '"') + .replace(/\u201C/g, '"') + .replace(/\u201D/g, '"') + .replace(/\u201E/g, '"') + .replace(/\u201F/g, '"'); +} + module.exports = class Command { constructor(body, callback) { Object.assign(this, body); this.callback = callback; + this.text = normalizeQuotes(this.text); // Check for subcommand in the command text const match = this.text.match(SUBCOMMAND); diff --git a/test/slack/command.test.js b/test/slack/command.test.js index c12d2a863..f4d0ed6e6 100644 --- a/test/slack/command.test.js +++ b/test/slack/command.test.js @@ -39,4 +39,55 @@ describe('Command class', () => { 'area/api', ]); }); + + describe('normalizes unicode quotes', () => { + test("supports '\u00AB'", () => { + const command = new Command({ + text: 'subscribe integration/jira +label:«help wanted«', + }); + expect(command.text).toEqual('integration/jira +label:"help wanted"'); + }); + + test("supports '\u00BB'", () => { + const command = new Command({ + text: 'subscribe integration/jira +label:»help wanted»', + }); + expect(command.text).toEqual('integration/jira +label:"help wanted"'); + }); + + test("supports '\u201C'", () => { + const command = new Command({ + text: 'subscribe integration/jira +label:“help wanted“', + }); + expect(command.text).toEqual('integration/jira +label:"help wanted"'); + }); + + test("supports '\u201D'", () => { + const command = new Command({ + text: 'subscribe integration/jira +label:”help wanted”', + }); + expect(command.text).toEqual('integration/jira +label:"help wanted"'); + }); + + test("supports '\u201E'", () => { + const command = new Command({ + text: 'subscribe integration/jira +label:„help wanted„', + }); + expect(command.text).toEqual('integration/jira +label:"help wanted"'); + }); + + test("supports '\u201F'", () => { + const command = new Command({ + text: 'subscribe integration/jira +label:‟help wanted‟', + }); + expect(command.text).toEqual('integration/jira +label:"help wanted"'); + }); + + test('supports combining multiple types of quotes in one command', () => { + const command = new Command({ + text: 'subscribe integration/jira +label:»help wanted«', + }); + expect(command.text).toEqual('integration/jira +label:"help wanted"'); + }); + }); });