adam-cowley/neode

Wrong key parsing in Builder._addWhereParameter()

gueno-dev opened this issue · 0 comments

Hi, I noticed a strange bug in the _addWhereParameter method.
This method create a unique key at this point :

let base = `where_${key.replace(/[^a-z0-9]+/, '_')}`;

If the node alias includes a special char like "_", this unique key is broken because the regex only match the first occurrence of special chars. This behavior throw an error in Neo4j.

Example :

For alias = p :

{
  query: 'MATCH (p:ResourceContent) WHERE (p.title = $where_p_title) RETURN p',
  params: { where_p_title: 'My title' }
}

--> No problem, this query works.

For alias = p_p :

{
  query: 'MATCH (p_p:ResourceContent) 'WHERE (p_p.title = $where_p_p.title) RETURN p_p',
  params: { 'where_p_p.title': 'My title' }
}

--> A point is still present in the variable and it's throw an error :

Neo4jError: Expected parameter(s): where_p_p

I submit a fix, could you merge it, please ? Thanks :)