the-graph icon indicating copy to clipboard operation
the-graph copied to clipboard

the-graph-clipboard:makeNewId() makes bad Ids

Open davidmaxwaterman opened this issue 10 years ago • 2 comments

Perhaps this is a problem with the toJSON() function, but this is the origin of the problem. It creates node ids using the component, but the range of valid characters for component and process name are not the same - specifically, a component can contain the slash character '/', but processes cannot.

  var makeNewId = function (label) {
    var num = 60466176; // 36^5
    num = Math.floor(Math.random() * num);
    var id = label + '_' + num.toString(36);
    return id;
  };
...
     newNode.id = makeNewId(node.component);

This results in us having to post-process the process names to make them valid (but also introduces a source of potential bugs since we should really ensure the process names are still unique).

Any thoughts on this?

davidmaxwaterman avatar Aug 10 '15 20:08 davidmaxwaterman

there doesn't seem to be any check to see if the new id is actually already used...did I miss something, or are we assuming duplicate random numbers are so unlikely that it won't ever happen?

davidmaxwaterman avatar Aug 10 '15 20:08 davidmaxwaterman

Looks like we're not checking. I don't like that assumption!

forresto avatar Aug 10 '15 20:08 forresto