From e9abc5a4f083d722fd1a22bbcf509e57f1ee31e1 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Mon, 27 Apr 2020 10:17:04 -0500 Subject: [PATCH] Add workaround to exclude emoji from task escaping This closes #7459. --- ui/app/utils/escape-task-name.js | 17 ++++++++++++++++- ui/package.json | 1 + ui/tests/unit/utils/escape-task-name-test.js | 1 + ui/yarn.lock | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ui/app/utils/escape-task-name.js b/ui/app/utils/escape-task-name.js index fff0e4741f8..68d0276f207 100644 --- a/ui/app/utils/escape-task-name.js +++ b/ui/app/utils/escape-task-name.js @@ -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); + }); } diff --git a/ui/package.json b/ui/package.json index de8c684fe67..7fb87c0fe92 100644 --- a/ui/package.json +++ b/ui/package.json @@ -95,6 +95,7 @@ "ember-source": "~3.12.0", "ember-test-selectors": "^2.1.0", "ember-truth-helpers": "^2.0.0", + "emoji-regex": "^9.0.0", "eslint": "^5.16.0", "eslint-plugin-node": "^9.0.1", "faker": "^4.1.0", diff --git a/ui/tests/unit/utils/escape-task-name-test.js b/ui/tests/unit/utils/escape-task-name-test.js index b34ab2430ea..0d57cfe943a 100644 --- a/ui/tests/unit/utils/escape-task-name-test.js +++ b/ui/tests/unit/utils/escape-task-name-test.js @@ -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šŸ„³'); }); }); diff --git a/ui/yarn.lock b/ui/yarn.lock index 6688fd47433..b95ea42eed3 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -7586,6 +7586,11 @@ emoji-regex@^7.0.1: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== +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"