Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Add workaround to exclude emoji from task escaping #7813

Merged
merged 1 commit into from
Feb 9, 2021

Conversation

backspace
Copy link
Contributor

@backspace backspace commented Apr 27, 2020

This closes #7459.

While emoji don’t actually need escaping, expanding the
expression that enumerates all task name characters that
don’t need escaping to include emoji is prohibitive, since
it’s a discontinuous range. The emoji-regex project has
such an expression and it’s 12kB.

This fixes the regular expression to property escape emoji
as a single character instead of as its component bytes.
Thanks to @DingoEatingFuzz for the suggestion.

@github-actions
Copy link

github-actions bot commented Feb 3, 2021

Ember Asset Size action

As of c3e55c1

Files that got Bigger 🚨:

File raw gzip
nomad-ui.js +1 B 0 B

Files that stayed the same size 🤷‍:

File raw gzip
vendor.js 0 B 0 B
nomad-ui.css 0 B 0 B
vendor.css 0 B 0 B

@github-actions
Copy link

github-actions bot commented Feb 3, 2021

Ember Test Audit comparison

master c3e55c1 change
passes 1551 1551 0
failures 0 0 0
flaky 0 0 0
duration 8m 25s 134ms 8m 49s 333ms +24s 199ms

@DingoEatingFuzz
Copy link
Contributor

If I'm reading this correctly, the underlying issue is that String#replace doesn't handle 4-byte characters?

If that's the case you can use the regex u flag. Haphazardly copy-pasting code from your PR into dev tools yielded this:

str.replace(/[^a-zA-Z0-9,._+@%/-]/g, '\\$&');
// "emoji\�\�"
str.replace(/[^a-zA-Z0-9,._+@%/-]/gu, '\\$&');
// "emoji\🥳"

It looks like the emoji still match and get escaped but maybe that can be worked around without bringing in a dependency?

This closes #7459.

While emoji don’t actually need escaping, expanding the
expression that enumerates all task name characters that
don’t need escaping to include emoji is prohibitive, since
it’s a discontinuous range. The emoji-regex project has
such an expression and it’s 12kB.

This fixes the regular expression to property escape emoji
as a single character instead of as its component bytes.
Thanks to @DingoEatingFuzz for the suggestion.
@backspace
Copy link
Contributor Author

hah WELL that’s way better, thank you, TIL! I’ve overwritten with a much smaller commit 🤓

@@ -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\\🥳');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should emoji be escaped? Maybe it's harmless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don’t need to be but I can’t think of a way to exclude them from escaping while still escaping things that should be, at least without something like emoji-regex. I do believe it’s harmless to escape them: slightly unsightly, but emoji in task names are surely rare 🤔

The current approach to escaping a task name is “escape everything but these known-to-be-safe characters”. My previous implementation used emoji-regex to let emoji be treated as known-to-be-safe but it seems maybe overkill when escaping them this way doesn’t add much noise. The Stack Overflow answer that I linked to for the original regular expression has a more naïve suggestion to instead escape every character but that seems hideous to me 😆

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I agree with you that escaping everything is a nope. Since this is safe I'm happy with it 😄

@backspace backspace merged commit 24b9a89 into master Feb 9, 2021
@backspace backspace deleted the b-ui/exec-emoji-task-name branch February 9, 2021 15:33
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI: fix rendering of task name emoji in exec terminal command-editing
2 participants