From 8aa8e7b8763a404db96781d114abd8f3f58e8bbd Mon Sep 17 00:00:00 2001 From: Dennis Sivia Date: Thu, 29 Aug 2019 10:11:20 +0200 Subject: [PATCH] Add support for unicode quotes in commands (#927) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add support for unicode quotes in commands Quoting spaces in required-label filters is possible via `"` (ASCII 34) and `'` (ASCII 39). This already led to some confusing, when users typed `“` (3-byte Unicode). `@wilhelmklopp` anticipated this and we already discussed a solution that is implemented by this PR. We now support multiple common Unicode quotes by converting them into double quotes (ASCII-34). ``` ✓ supports '«' ✓ supports '»' ✓ supports '“' ✓ supports '”' ✓ supports '„' ✓ supports '‟' ``` --- lib/slack/command.js | 11 ++++++++ test/slack/command.test.js | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) 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"'); + }); + }); });