From 42067f3ce700749b3f293bd4efd914257cb797f9 Mon Sep 17 00:00:00 2001 From: Oskar Hane Date: Tue, 23 May 2017 11:19:50 +0200 Subject: [PATCH] Fix errors for semicolons within quotes --- src/shared/services/commandUtils.js | 10 ++++++++++ src/shared/services/commandUtils.test.js | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/shared/services/commandUtils.js b/src/shared/services/commandUtils.js index 4d6e08c22c9..cc4b0615e32 100644 --- a/src/shared/services/commandUtils.js +++ b/src/shared/services/commandUtils.js @@ -87,9 +87,19 @@ export const getInterpreter = (interpret, cmd, cmdchar) => { export const isNamedInterpreter = (interpreter) => interpreter && interpreter.name !== 'catch-all' export const extractPostConnectCommandsFromServerConfig = (str) => { + const substituteStr = '@@semicolon@@' + const substituteRe = new RegExp(substituteStr, 'g') + const replaceFn = (m) => m.replace(/;/g, substituteStr) + const qs = [ + /(`[^`]*?`)/g, + /("[^"]*?")/g, + /('[^']*?')/g + ] + qs.forEach((q) => (str = str.replace(q, replaceFn))) const splitted = str .split(';') .map((item) => item.trim()) + .map((item) => item.replace(substituteRe, ';')) .filter((item) => item && item.length) return splitted && splitted.length ? splitted : undefined } diff --git a/src/shared/services/commandUtils.test.js b/src/shared/services/commandUtils.test.js index f7a69bf29c7..2db2efa43c2 100644 --- a/src/shared/services/commandUtils.test.js +++ b/src/shared/services/commandUtils.test.js @@ -126,7 +126,12 @@ describe('commandutils', () => { { str: ':play cypher ;', expect: [':play cypher'] }, { str: ';:play cypher;', expect: [':play cypher'] }, { str: ':play cypher; :param x: 1', expect: [':play cypher', ':param x: 1'] }, - { str: 'RETURN 1; RETURN 3; :play start', expect: ['RETURN 1', 'RETURN 3', ':play start'] } + { str: 'RETURN 1; RETURN 3; :play start', expect: ['RETURN 1', 'RETURN 3', ':play start'] }, + { str: 'MATCH (n: {foo: "bar;", bar: "foo;"}) RETURN n', expect: ['MATCH (n: {foo: "bar;", bar: "foo;"}) RETURN n'] }, + { str: 'MATCH (n: {foo: \'bar;\'}) RETURN n', expect: ['MATCH (n: {foo: \'bar;\'}) RETURN n'] }, + { str: 'MATCH (n: {foo: `bar;`}) RETURN n', expect: ['MATCH (n: {foo: `bar;`}) RETURN n'] }, + { str: 'MATCH (n: {foo: `bar;;`}) RETURN n', expect: ['MATCH (n: {foo: `bar;;`}) RETURN n'] }, + { str: ':play cypher; MATCH (n: {foo: `bar; en;`}) RETURN n', expect: [':play cypher', 'MATCH (n: {foo: `bar; en;`}) RETURN n'] } ] // When & Then