AbimannanMuthusamy / jsplumb

Automatically exported from code.google.com/p/jsplumb
0 stars 0 forks source link

the getElementObject for jQuery doesn't always work #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a div element with non-alphanumeric characters (ie. 
id="addressBookList[0].id")
2. Try to add an anchor to that element

What is the expected output? What do you see instead?
An anchor is expected. Depending on whether the element or its id is specified, 
it may or may not be draw. However down the line, when other methods are called 
(ie. repaintEverything) that reference the getElementObject object fails.

From jQuery docs: http://api.jquery.com/category/selectors/

If you wish to use any of the meta-characters (#;&,.+*~':"!^$[]()=>|/@ ) as a 
literal part of a name, you must escape the character with two backslashes: \\.

This can be done programmatically in jsPlumb's code as follow...

getElementObject : function(el) {
                        el = el.replace(/(\[|\]|\.)/g, '\\\\$1');
            return typeof(el)=='string' ? $("#" + el) : $(el);
        }

The above will escape ".", "[", "]" -- but the regex should be expanded to esc. 
everything.

Original issue reported on code.google.com by adambenjaminvarga on 8 Oct 2010 at 8:00

GoogleCodeExporter commented 9 years ago
Actually the fix I suggest doesn't work... but I wanted to at least report the 
problem.

Original comment by adambenjaminvarga on 8 Oct 2010 at 8:02

GoogleCodeExporter commented 9 years ago
i'm not sure that this would be jsPlumb's responsibility, really.  like the 
docs say, if you want to use an id with characters like that, you must escape 
the characters.  

also, i wouldn't be overly keen to add a piece of code that is executed on a 
heavily trafficked method to cover what is almost certainly a very small 
percentage of cases.

if it works for you when passing in an escaped string to jsplumb then i don't 
think there's anything to do here.

Original comment by simon.po...@gmail.com on 8 Oct 2010 at 10:56

GoogleCodeExporter commented 9 years ago
any updates on this? i'm about to do a release and i'm gonna close it out 
unless you have an update....

Original comment by simon.po...@gmail.com on 12 Oct 2010 at 8:24

GoogleCodeExporter commented 9 years ago
I'm using jsPlumb in a Chrome extension that injects javascript into all sorts 
of web pages. If I had control of the web pages it was injecting into, I'd 
avoid any non-alphanumeric characters and this wouldn't be an issue. Inputs 
with these funky characters are definitely an edge case for me. There are a few 
spots were jsPlumb converts objects to and from ids... I unfortunately can't 
get around this issue by just feeding jsPlumb the input object instead of its 
id. I can have my extension strip non alpha number characters from the ids 
before passing then to the plugins, but I think it would be cleaner if I didn't 
have to.

Original comment by adambenjaminvarga on 12 Oct 2010 at 9:00

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
sounds interesting!

my concern is the performance hit from running that regex inside a method that 
gets called a lot.  but then it is kind of appealing to make it more robust.  

does your extension include any other JS? have you considered that you could 
override that method by including a JS snippet like this, after the jsPlumb 
include:

jsPlumb.CurrentLibrary.getElementObject = function(el) {            
  return typeof(el)=='string' ? $("#" + el.replace(/(\[|\]|\.)/g, '\\\\$1')) : $(el);
};

?

Original comment by simon.po...@gmail.com on 13 Oct 2010 at 9:45

GoogleCodeExporter commented 9 years ago
i'm closing this.  there's a documented fix and i'm reluctant to put it in the 
jsPlumb core.

Original comment by simon.po...@gmail.com on 23 Nov 2010 at 9:17