Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Strip color codes from notifications #634

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Strip color codes from notifications #634

wants to merge 1 commit into from

Conversation

sprusr
Copy link

@sprusr sprusr commented Feb 1, 2016

Fixes #628

@dgw
Copy link

dgw commented Feb 2, 2016

This should probably strip all control codes, not just colors.

  • \x02: bold text
  • \x03: colored text (already handled with arguments, 👍)
  • \x1D: italic text
  • \x1F: underlined text
  • \x16: swap background and foreground colors ("reverse video")
  • \x0F: reset all formatting

@sprusr
Copy link
Author

sprusr commented Feb 2, 2016

Hey @dgw thanks for the suggestion. Initially I thought it wouldn't be necessary to handle these, as they represent characters that won't be displayed, but I suppose it depends on the situation.
Will make the changes suggested, thanks again.

@dgw
Copy link

dgw commented Feb 2, 2016

If only worrying about characters that are displayed, there's no reason to remove \x03 from colors; just removing the digits would suffice. 😉

Thanks for updating the PR. I figured (and should have explained initially) that it's best to remove all of the control codes in case of misbehaving fonts, or other weirdness that could arise from having non-printing characters in the notifications. There are a lot of system configurations out there, and as long as we're stripping one kind of control character…

💯👍

@xPaw
Copy link
Contributor

xPaw commented Feb 2, 2016

👍 However, this probably conflicts #627 as that PR moves code around.

@@ -655,7 +655,7 @@ $(function() {
favico.badge("!");
if (settings.badge && Notification.permission === "granted") {
var notify = new Notification(msg.from + " says:", {
body: msg.text.trim(),
body: msg.text.trim().replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:\d{1,2}(?:,\d{1,2})?)?/, ""),
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it should trim after replace?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, thanks for noticing that. Will make suggested change.

Copy link
Contributor

Choose a reason for hiding this comment

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

While you're at it, change \d to [0-9]. See http://stackoverflow.com/a/6479605/2200891

@sprusr
Copy link
Author

sprusr commented Feb 2, 2016

My apologies for the number of commits this is taking for a single regex! I haven't made much contribution to open source projects before, so thank you for being so helpful along the way.

@AlMcKinlay
Copy link
Contributor

Don't worry about that, @sprusr, we all have to start somewhere :-)

The only thing is that before this gets merged, it'll be good to squash the commits into 1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants