Skip to content

Commit

Permalink
Add workaround to exclude emoji from task escaping
Browse files Browse the repository at this point in the history
This closes #7459.
  • Loading branch information
backspace committed Feb 3, 2021
1 parent 4e0e33e commit 01746ed
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ui/app/utils/escape-task-name.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import emojiRegex from 'emoji-regex';

export default function escapeTaskName(taskName) {
// Store emoji character components differently to bypass escaping:
// "string🥳" becomes "stringUNICODE55358.UNICODE56691."
const taskNameWithTransformedEmoji = taskName.replace(emojiRegex(), emoji => {
return emoji.split('').map(char => {
return `UNICODE${char.charCodeAt(0)}.`;
}).join('');
});

// Regular expression is taken from here: https://stackoverflow.com/a/20053121
return taskName.replace(/[^a-zA-Z0-9,._+@%/-]/g, '\\$&');
const escaped = taskNameWithTransformedEmoji.replace(/[^a-zA-Z0-9,._+@%/-]/g, '\\$&');

// Restore temporarily-transformed emoji
return escaped.replace(/UNICODE(\d+)./g, (match, digits) => {
return String.fromCharCode(digits);
});
}
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"ember-template-lint": "^2.9.0",
"ember-test-selectors": "^2.1.0",
"ember-truth-helpers": "^2.0.0",
"emoji-regex": "^9.0.0",
"eslint": "^5.16.0",
"eslint-plugin-ember": "^7.7.2",
"eslint-plugin-ember-a11y-testing": "a11y-tool-sandbox/eslint-plugin-ember-a11y-testing#ca31c9698c7cb105f1c9761d98fcaca7d6874459",
Expand Down
1 change: 1 addition & 0 deletions ui/tests/unit/utils/escape-task-name-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module('Unit | Utility | escape-task-name', function() {
assert.equal(escapeTaskName('plain'), 'plain');
assert.equal(escapeTaskName('a space'), 'a\\ space');
assert.equal(escapeTaskName('dollar $ign'), 'dollar\\ \\$ign');
assert.equal(escapeTaskName('emoji🥳'), 'emoji🥳');
});
});
5 changes: 5 additions & 0 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7733,6 +7733,11 @@ emoji-regex@^8.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==

emoji-regex@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.0.0.tgz#48a2309cc8a1d2e9d23bc6a67c39b63032e76ea4"
integrity sha512-6p1NII1Vm62wni/VR/cUMauVQoxmLVb9csqQlvLz+hO2gk8U2UYDfXHQSUYIBKmZwAKz867IDqG7B+u0mj+M6w==

emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
Expand Down

0 comments on commit 01746ed

Please sign in to comment.