Skip to content

Commit

Permalink
Add support for unicode quotes in commands (#927)
Browse files Browse the repository at this point in the history
* 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 '‟'
```
  • Loading branch information
Dennis Sivia authored Aug 29, 2019
1 parent 5b7cbdd commit 8aa8e7b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/slack/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
51 changes: 51 additions & 0 deletions test/slack/command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
});
});
});

0 comments on commit 8aa8e7b

Please sign in to comment.