-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workaround to exclude emoji from task escaping
This closes #7459.
- Loading branch information
Showing
4 changed files
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
import emojiRegex from 'emoji-regex'; | ||
|
||
export default function escapeTaskName(taskName) { | ||
// Regular expression is taken from here: https://stackoverflow.com/a/20053121 | ||
return taskName.replace(/[^a-zA-Z0-9,._+@%/-]/g, '\\$&'); | ||
// Store emoji character components differently to bypass escaping: | ||
// "string🥳" becomes "stringUNICODE55358.UNICODE56691." | ||
const taskNameWithTransformedEmoji = taskName.replace(emojiRegex(), (a,b,c,d) => { | ||
return a.split('').map(char => { | ||
return `UNICODE${char.charCodeAt(0)}.`; | ||
}).join(''); | ||
});; | ||
|
||
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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters