Skip to main content

Bug Tracker

Side navigation

#11458 closed enhancement (wontfix)

Opened March 09, 2012 06:37AM UTC

Closed March 09, 2012 01:46PM UTC

Last modified March 09, 2012 02:20PM UTC

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

Reported by: millermedeiros Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
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.

Attachments (0)
Change History (2)

Changed March 09, 2012 01:46PM UTC by dmethvin comment:1

resolution: → wontfix
status: newclosed

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.

Changed March 09, 2012 02:20PM UTC by millermedeiros comment:2

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.