Bug Tracker

Modify

Ticket #11458 (closed enhancement: wontfix)

Opened 2 years ago

Last modified 2 years ago

Event namespace should allow special chars like "+", "$", "/"

Reported by: millermedeiros Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

It could be fixed by escaping the namespace string before doing the split().sort().join()

// chars that should be escaped in RegExp constructor
var rEscapeRegExpChars = /[\\.+*?\^$\[\](){}\/'#]/g;

function escapeRegExp(str) {
    return str.replace(rEscapeRegExpChars,'\\$&');
}

// than later on the place where namespaces RegExp is created
namespaces = namespaces ? new RegExp("(^|\\.)" + escapeRegExp(namespaces).split("\\.").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
//

I was trying to create a namespace to handle keys combinations like "keypress.ctrl+s" but the "+" breaks unbind() and off() since namespaces.test( handleObj.namespace ) will return false.

My solution for now was simply to avoid using chars that have special meaning inside RegExp (using "keypress.ctrl_s" instead).

Couldn't find any information about it in the documentation and it took a while to realize the the event wasn't being removed and that the problem was caused by the plus sign.

Change History

comment:1 Changed 2 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to wontfix

I don't think it's necessary to accept any special characters, and doing so may limit our ability to expand syntax later. Use an underscore instead.

comment:2 Changed 2 years ago by millermedeiros

ok, totally understand and main reason why I didn't even asked for a pull request.

already implemented it here:  https://github.com/tzuryby/jquery.hotkeys/pull/20

good thing that now it's documented somewhere (here in the bug tracker) and explains why it works this way.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.